tags:

views:

76

answers:

1

Hi,

I've got a xaml of a window with an unnamed border control somewhere inside. The border control uses an attached property that I wrote and the attached property basically sets the border control's Name property to a known value, like "placeholder". After the window is loaded, it tries to find that border control through the name that attached property gave it.

The problem is that it doesn't seem to work. Window.FindName returns null. Any ideas?

Edit: The border control does get named before the Window.FindName gets called, so it's not that it hasn't been named in time.

As an alternate solution, I was thinking of just going through the window's children and find the one that uses my attached property. How would I do that?

Thanks!

+1  A: 

To verify that the border is getting named correctly, you can run Snoop. This will show you the visual tree of your application, and all of the properties of every control.

If you want to enumerate the visual tree yourself, you can use the VisualTreeHelper class. Specifically, the GetChildrenCount() and GetChild() methods can be called to traverse the visual tree.

Andy
Instead of setting a Name and using window.FindName, I'm using the VisualTreeHelper to find a control that has the attached property I'm looking for. Thanks Andy!
Steve the Plant