#108 – The Logical Tree
October 28, 2010 4 Comments
In WPF, the logical tree is the hierarchy of elements that make up your user interface. If your user interface is defined in XAML, the logical tree is the set of elements from the XAML, organized into a tree based on their parent/child relationships.
The logical tree can also be thought of as a model that describes the relationships between objects at runtime. Knowing the logical tree can be helpful in understanding:
- Resource lookup
- Property inheritance
- Event routing
As an example, the logical tree for the following XAML:
<Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="A window.." Height="350" Width="525"> <StackPanel> <Button Content="Click Me" Height="23" HorizontalAlignment="Left" Width="75" Click="button1_Click" /> <TextBox /> <ListBox> <ListBoxItem Content="Barley"/> <ListBoxItem Content="Oats"/> </ListBox> </StackPanel> </Window>
looks like this:
Pingback: #109 – Navigating the Logical Tree in Code « 2,000 Things You Should Know About WPF
Pingback: An Application to Let You View WPF Logical Trees « Sean’s Stuff
Pingback: #837 – A Window Cannot Be a Child of a ContentControl | 2,000 Things You Should Know About WPF
Pingback: #994 – Viewing the Visual Tree from within Visual Studio | 2,000 Things You Should Know About WPF