XAML TreeView

XAML <TreeView> element represents a TreeView control in WPF. Here are a few XAML TreeView code examples.

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. 
  1. <TreeView Margin="10,10,0,13" Name="TreeView1" HorizontalAlignment="Left"  
  2. 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. 
  1. <TreeView Margin="10,10,0,13" Name="TreeView1" HorizontalAlignment="Left"  
  2. VerticalAlignment="Top" Width="194" Height="200">  
  3. <TreeViewItem Header="Cold Drinks">  
  4. <TreeViewItem Header="Coke"></TreeViewItem>  
  5. <TreeViewItem Header="Pepsi"></TreeViewItem>  
  6. <TreeViewItem Header="Orange Juice"></TreeViewItem>  
  7. <TreeViewItem Header="Milk"></TreeViewItem>  
  8. <TreeViewItem Header="Iced Tea"></TreeViewItem>  
  9. <TreeViewItem Header="Mango Shake"></TreeViewItem>  
  10. </TreeViewItem>  
  11. </TreeView>  
You can write a double click event handler on a TreeViewItem to execute some code when a TreeView item is double clicked.
  1. <TreeViewItem Header="Dad" Foreground="Blue" MouseDoubleClick="TreeViewItem_MouseDoubleClick">  
And implement event handler in your code behind. 
  1. private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)  
  2. {  
  3.   
  4. }  
To avoid duplicate content, the article has moved here: WPF TreeView Tutorial