0

I have a library DLL, and a WPF test exe that depends on the said library. Here's the test exe:

using MyLibrary;

namespace WpfTest
{
    public partial class Window2 : Window
    {
        private MyLibrary _mylib;

        public Window2()
        {
            InitializeComponent();
            this.Loaded += window2Loaded;
        }

        void window2Loaded(object sender, RoutedEventArgs e)
        {
            _mylib = new MyLibrary(this);
        }
    }
}

In the MyLibrary class (in the DLL), I have the following constructor:

    public MyLibrary (System.Windows.Window window) // BREAKPOINT HERE.
    {
        ...

At the breakpoint above, the debugger shows the TextBlock (tb_mp) I want to access:

enter image description here

What do i need to do so that when I type window.tb_ in Visual Studio, IntelliSense will offer to complete it as window.tb_mp?

Sabuncu
  • 5,095
  • 5
  • 55
  • 89

1 Answers1

2

Nothing, you can't. The Locals widnow shows an envelope icon next to the tb_mp local, that means it's an internal member (see here: https://msdn.microsoft.com/en-us/library/y47ychfe(v=vs.100).aspx ). Visual Studio's intellisense window won't list members you don't have access to, in this case, internal members from another project.

There are three options:

  1. Change the access-modifier (in the original project) to public

  2. Use reflection to access the field (e.g. FieldInfo fi = window.GetType().GetField("tb_mp"))

  3. Iterate through controls in a window by using VisualTreeHelper. This is a more complicated topic, discussed at length here: How can I find WPF controls by name or type? and here: WPF: How do I loop through the all controls in a window?

Community
  • 1
  • 1
Dai
  • 141,631
  • 28
  • 261
  • 374
  • Thank you. To this day I was unaware of the envelope icon, let alone knew its meaning! Providing `x:FieldModifier="public"` for `tb_mp` opened up access to it, but I also had to cast the `window` variable as `((WpfTest.Window2)` (as well as supply the namespace, of course) for IntelliSense to kick in. – Sabuncu Sep 16 '15 at 20:51