Posted by: Zeeshan Amjad | October 2, 2009

Introduction to Tree view control in XAML


Using Tree control in WPF is very easy. We can display hierarchal data in the tree control. Here is a simple XAML code to make a tree control.

  1: <Window x:Class="TreeView.Window1"
  2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4:     Title="Tree View" Height="300" Width="300" Loaded="Window_Loaded">
  5:     <Grid>
  6:         <TreeView Margin="5"  Background="LightYellow" >
  7:             <TreeViewItem Header="Maryland">
  8:                 <TreeViewItem Header="Annapolis"></TreeViewItem>
  9:                 <TreeViewItem Header="Baltimore"></TreeViewItem>
 10:             </TreeViewItem>
 11:             <TreeViewItem Header="California">
 12:                 <TreeViewItem Header="Los Angeles"></TreeViewItem>
 13:                 <TreeViewItem Header="San Francisco"></TreeViewItem>
 14:                 <TreeViewItem Header="San Diego"></TreeViewItem>
 15:                 <TreeViewItem Header="sacramento"></TreeViewItem>
 16:             </TreeViewItem>
 17:             <TreeViewItem Header="Massachusetts">
 18:                 <TreeViewItem Header="Boston"></TreeViewItem>
 19:             </TreeViewItem>            
 20:         </TreeView>
 21:     </Grid>
 22: </Window>
 23: 

Here is the output of this program.

 

TreeView

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: