Posted by: Zeeshan Amjad | October 4, 2009

Using Radio Button in Tree View in WPF

Using Radio button in Tree control is very easy in WPF. Instead of using TreeViewItem, we simply make RadioButton class and make it a child of TreeView item. Here is a simple XAML code to make radio button in Tree View control.

  1: <Window x:Class="TreeView.Window1"
  2:     xmlns=""
  3:     xmlns:x=""
  4:     Title="Tree View" Height="300" Width="300" Loaded="Window_Loaded">
  5:     <Grid>
  6:         <TreeView Name="tree" Margin="5"  Background="LightYellow" >
  7:             <TreeViewItem Header="Maryland">
  8:                 <RadioButton>Annapolis</RadioButton>
  9:                 <RadioButton>Baltimore</RadioButton>
 10:             </TreeViewItem>
 11:             <TreeViewItem Header="California">
 12:                 <RadioButton>Los Angeles</RadioButton>
 13:                 <RadioButton>San Francisco</RadioButton>
 14:                 <RadioButton>San Diego</RadioButton>
 15:                 <RadioButton>Sacramento</RadioButton>
 16:             </TreeViewItem>
 17:             <TreeViewItem Header="Washington">
 18:                 <RadioButton>Olympia</RadioButton>
 19:                 <RadioButton>Seattle</RadioButton>
 20:             </TreeViewItem>
 21:         </TreeView>
 22:     </Grid>
 23: </Window>

Here is the output of this program.




Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s


%d bloggers like this: