WPFwiki, wpf, wiki, .net 3.0, windows presentation foundation, FAQ, free resources, solution, development, microsoft Home of the world's largest WPF FAQ

Q7.1 - Logical Tree vs. Visual Tree

Modified: Fri, 16 Mar 2007 15:18 by Jenny - Categorized as: WPF FAQ
Edit

Category

Fundamentals

Edit

Question

What is the difference between the Logical Tree and the Visual Tree?

Edit

Answer

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
              +....


Edit

Keywords

visual, logical tree, visualtree, logicaltree

All content is Copyright ©2007 Xceed Software Inc. unless otherwise indicated. See the Terms of Service. Contributors must read and agree to the Contribution Policy. WPFwiki is brought to you by Xceed, makers of the powerful yet free Xceed DataGrid for WPF.