-2

I just want to see visual elements of controls, and to do it I created a really basic window which contains two labels and button. The problem is that I can't see any visual as I expected either in VisualTreeHelper or visual studio's tool named "WPF Tree Visualizer".

Current project

The weird part is that it works in my another project.

Another project

What may cause of this? Why it doesn't work as in my other project?

1 Answers1

1

Looks like you are calling the code in the constructor. Try calling the same code in the window loaded event and you should see a difference.

Jesse Good
  • 50,901
  • 14
  • 124
  • 166
  • Well, I didn't realize that I should use Visual Tree structure in loaded event. It works not, thanks for the answer – Canberk Nov 04 '21 at 11:35
  • [This page](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/object-lifetime-events?view=netframeworkdesktop-4.8) gives a good explanation. Basically, the visual tree has not been created yet when the constructor is called. – Jesse Good Nov 04 '21 at 12:10