The XAML TreeView element represents a TreeView control in WPF. The code in this article are examples of using a XAML TreeView element.
XAML TreeView element to declare the TreeView control.
- <TreeView Margin="10,10,0,13" Name="TreeView1" HorizontalAlignment="Left"
- VerticalAlignment="Top" Width="194" Height="200" />
A TreeView is a collection of TreeViewItem elements. The following XAML code adds a few TreeViewItem element to the control.
- <TreeView Margin="10,10,0,13" Name="TreeView1" HorizontalAlignment="Left"
- VerticalAlignment="Top" Width="194" Height="200">
- <TreeViewItem Header="Cold Drinks">
- <TreeViewItem Header="Coke"></TreeViewItem>
- <TreeViewItem Header="Pepsi"></TreeViewItem>
- <TreeViewItem Header="Orange Juice"></TreeViewItem>
- <TreeViewItem Header="Milk"></TreeViewItem>
- <TreeViewItem Header="Iced Tea"></TreeViewItem>
- <TreeViewItem Header="Mango Shake"></TreeViewItem>
- </TreeViewItem>
- </TreeView>
You can write a double click event handler on a TreeViewItem to execute some code when a TreeView item is double clicked.
- <TreeViewItem Header="Dad" Foreground="Blue" MouseDoubleClick="TreeViewItem_MouseDoubleClick">
And implement event handler in your code behind.
- private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
-
- }