Search This Blog

Monday, November 11, 2013

TreeView WPF Example

WPF > ControlsItemsControl > TreeView

TreeView displays hierarchical data in a tree structure and items can expand and collapse.
It can contain a collection of objects of any type (string, image,  panel).

Example:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Background="#FFF3EEEE">
    <TreeView HorizontalAlignment="Left" Height="320" VerticalAlignment="Top" Width="517">
        <TreeViewItem Header="Teachers">
            <TreeViewItem Header="Dan"/>
            <TreeViewItem Header="John"/>
        </TreeViewItem>
        <TreeViewItem Header="Students">
            <TreeViewItem Header="Eric" IsExpanded="True">
                <StackPanel Height="102" VerticalAlignment="Top" Width="177">
                    <TabControl Height="100">
                        <TabItem Header="School">
                            <Grid Background="#FFE5E5E5">
                                <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Eric Elementary School" VerticalAlignment="Top"/>
                            </Grid>
                        </TabItem>
                        <TabItem Header="Notes">
                            <Grid Background="#FFE5E5E5"/>
                        </TabItem>
                    </TabControl>
                </StackPanel>
            </TreeViewItem>
        </TreeViewItem>
    </TreeView>
</Window>




Other examples: