EditCategory
Fundamentals
EditQuestion
What is the difference between the Logical Tree and the Visual Tree?
EditAnswer
The Logical Tree is a tree structure that represents the hierarchy of controls and elements that constitute a piece of user interface in WPF, but without their inner parts.
For example, if a DockPanel contains a ListBox which contains a list of Buttons, the Logical Tree will consist of the following:
DockPanel
+ListBox
+Button
+Button
+Button
The Visual Tree is a tree structure that represents the fine-grained hierarchy of Visuals that constitute what appears on the screen. It contains the same elements as the Logical Tree, but includes all the Visuals that are used to compose the Logical Tree's controls and elements, like the ControlTemplates and DataTemplates.
The Visual Tree of the previous example would therefore be as follows:
DockPanel
+ListBox
+Border
+...
+VirtualizingStackPanel
+ListBoxItem
+Button
+Border
+....
EditKeywords
visual, logical tree, visualtree, logicaltree