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

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

We can find them here

No comments:

Post a Comment