views:

82

answers:

3

Sorry for a potentially dumb question, I am still new at this. I really appreciate your help. Referring to http://stackoverflow.com/questions/1536739/c-get-control-by-name/1536756#1536756 But I don't have a "this.Controls" available. Is there something I am missing here?

In other words, when I type "this." and visual studio populates a list of option, there is no "Controls" option.

A: 

The link you gave was for Winforms, you are looking for a WPF way to do it which is different.

Brian R. Bondy
+3  A: 

In WPF, you should try this.FindName(string name)

Button b = (Button)this.FindName("button1");
Anthony Pegram
+1  A: 

If you are looking to iterate through the controls for whatever reason, in your Window class, you can iterate through the LayoutRoot's children (e.g.)

    foreach (object o in this.LayoutRoot.Children)
    {
        MessageBox.Show(o.GetType().Name);
    }

Keep in mind that the children can also contain children, so you'll need to delve into each of those as needed.

Robaticus