<UserControl x:Class="RadGridViewTemplateBug.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
     xmlns:telerikData="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" 
     xmlns:telerik="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" 
     xmlns:Controls1="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
     xmlns:local="clr-namespace:RadGridViewTemplateBug"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

    <UserControl.Resources>
        <local:BooleanToVisibiltyConverter x:Key="BooleanToVisibilityConverter"></local:BooleanToVisibiltyConverter>
        <!-- ********** GRID VIEW HEADER ROW RESOURCES ********** -->
        <SolidColorBrush x:Key="GridViewHeaderRowDataCellsPresenterBackground" Color="Transparent"/>
        <Controls1:Office_BlackTheme x:Key="Theme"/>
        <SolidColorBrush x:Key="GridViewHeaderCellBorderBrush" Color="#FFB3B3B3"/>
        <SolidColorBrush x:Key="GridViewHeaderCellInnerBorderBrush" Color="#FFEEEEEE"/>
        <DataTemplate x:Key="GridViewHeaderIndentCellDataTemplate">
            <telerik:GridViewHeaderIndentCell Controls1:StyleManager.Theme="{StaticResource Theme}"/>
        </DataTemplate>
        <ControlTemplate x:Key="GridViewHeaderRowTemplate" TargetType="telerik:GridViewHeaderRow">
            <Border x:Name="PART_GridViewHeaderRowBorder" Margin="{TemplateBinding Margin}" MinHeight="{TemplateBinding MinHeight}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                <telerik:SelectiveScrollingGrid>
                    <telerik:SelectiveScrollingGrid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </telerik:SelectiveScrollingGrid.ColumnDefinitions>
                    <telerik:DataCellsPresenter x:Name="PART_DataCellsPresenter" MinHeight="{TemplateBinding MinHeight}" Background="{StaticResource GridViewHeaderRowDataCellsPresenterBackground}" Grid.Column="3" Controls1:StyleManager.Theme="{StaticResource Theme}"/>
                    <Border x:Name="PART_IndicatorPresenter" MinHeight="{TemplateBinding MinHeight}" VerticalAlignment="Stretch" Width="24" Visibility="{TemplateBinding RowIndicatorVisibility}" BorderBrush="{StaticResource GridViewHeaderCellBorderBrush}" BorderThickness="0,0,1,0" telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical">
                        <Border Background="{TemplateBinding Background}" BorderBrush="{StaticResource GridViewHeaderCellInnerBorderBrush}" BorderThickness="0,0,1,1"/>
                    </Border>
                    <telerik:IndentPresenter x:Name="PART_IndentPresenter" MinHeight="{TemplateBinding MinHeight}" Grid.Column="1" ItemTemplate="{StaticResource GridViewHeaderIndentCellDataTemplate}" IndentLevel="{TemplateBinding IndentLevel}" telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" Controls1:StyleManager.Theme="{StaticResource Theme}"/>
                    <Border x:Name="PART_HierarchyIndentPresenter" MinHeight="{TemplateBinding MinHeight}" Width="24" Visibility="{Binding HasHierarchy, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="2" BorderBrush="Transparent" BorderThickness="0,0,1,0" telerik:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical">
                        <Border BorderBrush="{StaticResource GridViewHeaderCellInnerBorderBrush}" BorderThickness="0,0,1,1"/>
                    </Border>
                </telerik:SelectiveScrollingGrid>
            </Border>
        </ControlTemplate>
        <LinearGradientBrush x:Key="GridViewHeaderBackground" EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FFF8F8F9" Offset="0"/>
            <GradientStop Color="#FFDBDEE1" Offset="1"/>
            <GradientStop Color="#FFDFE2E5" Offset="0.4"/>
            <GradientStop Color="#FFC7CBD1" Offset="0.4"/>
        </LinearGradientBrush>
        <Style x:Key="GridViewHeaderRowStyle1" TargetType="telerik:GridViewHeaderRow">
            <Setter Property="Template" Value="{StaticResource GridViewHeaderRowTemplate}"/>
            <Setter Property="Background" Value="{StaticResource GridViewHeaderBackground}"/>
            <Setter Property="MinHeight" Value="26"/>
            <Setter Property="BorderThickness" Value="0,0,0,1"/>
            <Setter Property="BorderBrush" Value="{StaticResource GridViewHeaderCellBorderBrush}"/>
        </Style>

        <!-- ********** RELATED ORDERS TEMPLATE ********** -->
        <DataTemplate x:Key="relatedOrdersHierarchyChildTemplate">
            <telerik:GridViewDataControl AutoGenerateColumns="False"
                                            ItemsSource="{Binding RelatedOrders}"
					                      HeaderRowStyle="{StaticResource GridViewHeaderRowStyle1}">

                <telerik:GridViewDataControl.Columns>
                    <Controls:GridViewDataColumn Width="Auto" Header="Order Description">
                        <Controls:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding OrderDescription}" />
                            </DataTemplate>
                        </Controls:GridViewColumn.CellTemplate>
                    </Controls:GridViewDataColumn>
                </telerik:GridViewDataControl.Columns>
            </telerik:GridViewDataControl>
        </DataTemplate>

        <!-- ********** ORDERS TEMPLATE ********** -->
        <DataTemplate x:Key="ordersHierarchyChildTemplate">
            <telerik:GridViewDataControl AutoGenerateColumns="False"
                                         ItemsSource="{Binding Orders}"
                                          HierarchyChildTemplate="{StaticResource relatedOrdersHierarchyChildTemplate}"
				                          HeaderRowStyle="{StaticResource GridViewHeaderRowStyle1}">

                <telerik:GridViewDataControl.ChildTableDefinitions>
                    <Controls:GridViewTableDefinition>
                        <Controls:GridViewTableDefinition.Relation>
                            <telerikData:PropertyRelation ParentPropertyName="RelatedOrders"/>
                        </Controls:GridViewTableDefinition.Relation>
                    </Controls:GridViewTableDefinition>
                </telerik:GridViewDataControl.ChildTableDefinitions>

                <telerik:GridViewDataControl.Columns>
                    <Controls:GridViewDataColumn Width="Auto" Header="Order Description">
                        <Controls:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding OrderDescription}" />
                            </DataTemplate>
                        </Controls:GridViewColumn.CellTemplate>
                    </Controls:GridViewDataColumn>
                </telerik:GridViewDataControl.Columns>
            </telerik:GridViewDataControl>
        </DataTemplate>

    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <!-- ********** ROOT RADGRIDVIEW CONTROL ********** -->
        <Controls:RadGridView x:Name="radGridViewHierarchy" 
                              AutoGenerateColumns="False"
                              HierarchyChildTemplate="{StaticResource ordersHierarchyChildTemplate}"
                              HeaderRowStyle="{StaticResource GridViewHeaderRowStyle1}">

            <Controls:RadGridView.ChildTableDefinitions>
                <Controls:GridViewTableDefinition>
                    <Controls:GridViewTableDefinition.Relation>
                        <telerikData:PropertyRelation ParentPropertyName="Orders"/>
                    </Controls:GridViewTableDefinition.Relation>
                </Controls:GridViewTableDefinition>
            </Controls:RadGridView.ChildTableDefinitions>

            <Controls:RadGridView.Columns>
                <Controls:GridViewDataColumn Width="Auto" Header="Customer Name">
                    <Controls:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CustomerName}" />
                        </DataTemplate>
                    </Controls:GridViewColumn.CellTemplate>
                </Controls:GridViewDataColumn>
            </Controls:RadGridView.Columns>
        </Controls:RadGridView>
    </Grid>
</UserControl>
