XAML TreeView

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. {  
  4. }  
To avoid duplicate content, the article has moved here: WPF TreeView Tutorial  

Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.