Wednesday, July 23, 2014

WPF Visual Tree VS Logical Tree



Basically, logical tree elements are the ones we see on the UI and all other controls behind the scene that gets created in order to render them are includes in visual tree.

The Logical Tree

The logical tree describes the relations between elements of the user interface. The logical tree is responsible for:
  • Inherit DependencyProperty values
  • Resolving DynamicResources references
  • Looking up element names for bindings
  • Forwaring RoutedEvents

The Visual Tree

The visual tree contains all logical elements including all visual elements of the template of each element. The visual tree is responsible for:
  • Rendering visual elements
  • Propagate element opacity
  • Propagate Layout- and RenderTransforms
  • Propagate the IsEnabled property.
  • Do Hit-Testing
  • RelativeSource (FindAncestor)

Full article can be read from wpf helper site here 

http://wpftutorial.net/LogicalAndVisualTree.html


There are VisualTreeHelper and LogicalTreeHelper class as part of .NET frameworks.

We can find them here

http://msdn.microsoft.com/en-us/library/system.windows.logicaltreehelper%28v=vs.110%29.aspx

http://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper%28v=vs.110%29.aspx





No comments:

Post a Comment