TreeView control
TreeView control can be used for any data that can be represented in a hierarchy. The tree view provides an object oriented hierarchical or parent/child relationship view of data and meta-data. The most common example of a tree view is Windows Explorer's directory structure where disk drives contain folders, folders contain sub-folders and folders contain files.
property
Items Property - Items property is used to Initial collection of the nodes for the tree.
Foreground and Background property
The Background and Foreground property represents the background and foreground color of the TreeView control.
Now using Items property of the TreeView control to initial collection of the nodes.
XAML code
<Window x:Class="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">
<Grid x:Name="LayoutRoot" Background="White" Height="412">
<TreeView Height="400" HorizontalAlignment="Left" Margin="30,9,0,0" Name="TreeView1" VerticalAlignment="Top" Width="318" Background="SpringGreen">
<TreeViewItem Header="Item1" Name="TreeViewItem2" Foreground="Blue" Background="Aqua">
<TreeViewItem Header="Sub Item1" Foreground="Brown" Background="Tan">
<TreeViewItem Header="Example1" Foreground="DarkRed" Background="Teal" />
</TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="Item2" Background="SteelBlue" Name="TreeViewItem4">
<TreeViewItem Header="Sub Item1" Background="Yellow">
<TreeViewItem Header="Example1" Background="Yellow" />
</TreeViewItem>
<TreeViewItem Header="Sub Item2" Background="Crimson">
<TreeViewItem Header="Example1" Background="Teal" />
<TreeViewItem Header="Example2" Background="Plum" />
</TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="Item3" Background="Wheat" Foreground="Brown" Name="TreeViewItem5">
<TreeViewItem Header="Sub Item1" Background="YellowGreen">
<TreeViewItem Header="Example1" Background="Magenta" />
</TreeViewItem>
<TreeViewItem Header="Sub Item2" Name="TreeViewItem1" Background="Red">
<TreeViewItem Header="Example1" Background="Purple" />
<TreeViewItem Header="Example2" Background="CadetBlue" Foreground="Blue" />
</TreeViewItem>
<TreeViewItem Header="Sub Item3" Name="TreeViewItem3" Background="Yellow" Foreground="DarkGreen">
<TreeViewItem Header="Example1" Background="Indigo" Foreground="DarkRed" />
<TreeViewItem Header="Example2" Background="Lime" />
<TreeViewItem Header="Example3" Background="DarkBlue" />
</TreeViewItem>
</TreeViewItem>
</TreeView>
</Grid>
</Window>
Now run the application.
TreeView1.gif
Now expand all the nodes.
TreeView2.gif