Window.FindName cannot find the Border element that I named through the attached property

I have a xaml window with an unnamed border control somewhere inside. The border control uses the attached property that I wrote, and the attached property basically sets the Name property of the border control to a known value, such as "placeholder". After the window is loaded, it tries to find this border control through the name that it assigned.

The problem is that it does not work. Window.FindName returns null. Any ideas?

Edit: The border control gets the name before calling Window.FindName, so it does not mean that it was not named in time.

As an alternative solution, I was thinking of just going through the kids window and finding one that uses my attached property. How can I do it?

Thank!

+1
source share
1 answer

To make sure the border is correctly named, you can run Snoop . This will show you the visual tree of your application and all the properties of each control.

If you want to list the visual tree yourself, you can use the VisualTreeHelper class . In particular, the GetChildrenCount () and GetChild () methods can be called to move the visual tree.

+1
source

All Articles