Visual Tree and Logical Tree in WPF

In WPF all the elements and components are organised in a hierarchical structure or as a Tree Structure. This object tree structure helps in finding the relation between various elements of the WPF. This tree can be conceptualized in two ways Visual Tree and Logical Tree.

WPF provides two helper classes to traverse the Visual and Logical Trees, they are VisualTreeHelper Class and LogicalTreeHelper Class.

Logical Tree

All the elements / controls which are rendered in the User Interface form a hierarchical structure. This tree is known as Logical Tree. Generally the controls we write in XAML comprises the Logical Tree.

Need of Logical Tree

  • Used for Resource Lookup




Visual Tree

It is the core of all the controls that renders on screen. So visual tree comprises of all the visual elements which are inherited from the Visual Base class. You can think it like it comprises of all the logical elements plus the visual components of that control which make up it to render it on the screen.

Need of Visual Tree

  • Used for rendering elements. A control is rendered on screen by walking through the visual tree.
  • Routed Events travels through this tree.

Tip : A given Window/ Page/ Control can have only one Visual Tree but it can have multiple Logical Trees

We’ll be Back Soon !!!
This article is in updation process.. Sorry for Inconvenience..!!