<Window x:Class="WpfApplication16.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:local="clr-namespace:WpfApplication16">
    <Grid x:Name="layoutRoot">
        <Grid.Resources>
            <local:HierarchyButtonStyleSelector x:Key="hbss" />
            <local:HierarchyTemplateSelector x:Key="hts">
                <local:HierarchyTemplateSelector.L1HierarchyTemplate>
                    <DataTemplate>
                        <telerik:RadGridView ItemsSource="{Binding l2Items}" Name="childGrid1"  AutoGenerateColumns="False" >
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView>
                    </DataTemplate>
                </local:HierarchyTemplateSelector.L1HierarchyTemplate>
                <local:HierarchyTemplateSelector.L2HierarchyTemplate>                   
                        <DataTemplate>
                            <telerik:RadGridView ItemsSource="{Binding l2Items}" Name="childGrid1"  AutoGenerateColumns="False" >
                                <telerik:RadGridView.Columns>
                                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
                                </telerik:RadGridView.Columns>
                                <telerik:RadGridView.ChildTableDefinitions>
                                    <telerik:GridViewTableDefinition />
                                </telerik:RadGridView.ChildTableDefinitions>
                                <telerik:RadGridView.HierarchyChildTemplate>
                                    <DataTemplate>
                                        <telerik:RadGridView ItemsSource="{Binding l3Items}" Name="childGrid2"  AutoGenerateColumns="False" >
                                            <telerik:RadGridView.Columns>
                                                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
                                            </telerik:RadGridView.Columns>
                                        </telerik:RadGridView>
                                    </DataTemplate>
                                </telerik:RadGridView.HierarchyChildTemplate>
                            </telerik:RadGridView>
                        </DataTemplate>
                </local:HierarchyTemplateSelector.L2HierarchyTemplate>
            </local:HierarchyTemplateSelector>

        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <telerik:RadGridView x:Name="testGrid" ItemsSource="{Binding l1Items}" AutoGenerateColumns="False" Grid.Column="0" HierarchyChildTemplateSelector="{StaticResource hts}"  HierarchyExpandButtonStyleSelector="{StaticResource hbss}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition />
            </telerik:RadGridView.ChildTableDefinitions>
        </telerik:RadGridView>
        <StackPanel Grid.Column="1" Margin="10" >            
            <RadioButton GroupName="HierarchyGroup" x:Name="NoHierarchyButton"  Content="No hierarchy" Checked="HierarchyButton_Checked" IsChecked="true"/>
            <RadioButton GroupName="HierarchyGroup" x:Name="L1HierarchyButton" Content="Level1 hierarchy" Checked="HierarchyButton_Checked"/>
            <RadioButton GroupName="HierarchyGroup" x:Name="L2HierarchyButton" Content="Level2 hierarchy" Checked="HierarchyButton_Checked"/>
        </StackPanel>
    </Grid>
</Window>
