<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:local="clr-namespace:CustomTheme;assembly=CustomTheme"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                    
    
    xmlns:grid="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"
    xmlns:controls="clr-namespace:Telerik.Windows.Controls"
    
     >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Resources.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    
    
    <telerik:DoubleToGridLengthConverter x:Key="DoubleToGridLengthConverter" />

    <ControlTemplate x:Key="GridViewItemsControlTemplate" TargetType="grid:GridViewItemsControl">
        <Grid Background="{TemplateBinding Background}" x:Name="HierrarchyBackground">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition />


                <RowDefinition x:Name="ScrollBarRow" MinHeight="0"  Height="{Binding Source={StaticResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}, Converter={StaticResource DoubleToGridLengthConverter}}"/>


            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />

                <ColumnDefinition x:Name="ScrollBarColumn" MinWidth="0" Width="{Binding Source={StaticResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}, Converter={StaticResource DoubleToGridLengthConverter}}"/>


            </Grid.ColumnDefinitions>

            <grid:GridViewGroupPanel x:Name="PART_GroupPanel" Grid.ColumnSpan="2" Grid.Row="0" 
									 MinHeight="{TemplateBinding MinHeight}"
                                     Background="{TemplateBinding GroupPanelBackground}"
									 Foreground="{TemplateBinding GroupPanelForeground}"
									 BorderBrush="{TemplateBinding BorderBrush}"
									 BorderThickness="{TemplateBinding BorderThickness}"/>

            <StackPanel Grid.Row="1">

                <AdornerDecorator>

                    <grid:GridViewHeaderRow x:Name="PART_HeaderRow" IndentLevel="{TemplateBinding GroupCount}" 
                                        VerticalAlignment="Top" />

                </AdornerDecorator>

                <grid:GridViewNewRow x:Name="PART_AddNewRow" 
                                     IndentLevel="{TemplateBinding GroupCount}" 
                                     VerticalAlignment="Bottom" HorizontalAlignment="Left" Visibility="Collapsed" />
            </StackPanel>

            <grid:GridViewScrollViewer x:Name="PART_ItemsScrollViewer" CanHorizontallyScroll="True" Grid.Row="2" 
                                       Grid.RowSpan="2" Grid.ColumnSpan="2" >
                <grid:GridViewVirtualizingPanel  x:Name="PART_GridViewVirtualizingPanel" />
            </grid:GridViewScrollViewer>
            <Border x:Name="HierrarchyOuterBorder" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="3"
					BorderBrush="{StaticResource HierrarchyOuterBorderBrush}" BorderThickness="1" Visibility="Visible" />

            <grid:ScrollPositionIndicator Visibility="Collapsed" Margin="0,0,10,0" 
                                          IsHitTestVisible="False" HorizontalAlignment="Right" 
                                          Grid.Row="2" x:Name="PART_ScrollPositionIndicator" 
                                          
                                          IsScrolling="{TemplateBinding IsScrolling}"  
                                        Opacity="0"
                 />
            <Border x:Name="PART_FrozenColumnsPreview" Grid.Row="1" Visibility="Collapsed" HorizontalAlignment="Left" VerticalAlignment="Stretch" Grid.RowSpan="4" Background="#33000000" Width="5"/>



        </Grid>


        <ControlTemplate.Triggers>
            <Trigger Property="ScrollMode" Value="Deferred">
                <Setter Property="Visibility" TargetName="PART_ScrollPositionIndicator" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsScrolling" Value="true">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard TargetName="PART_ScrollPositionIndicator" TargetProperty="Opacity">
                            <DoubleAnimation Duration="0:0:0.0"  To="1" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard TargetName="PART_ScrollPositionIndicator" TargetProperty="Opacity">
                            <DoubleAnimation Duration="0:0:0.5"  To="0" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.ExitActions>
            </Trigger>
            <Trigger Property="ShowColumnHeaders" Value="false">
                <Setter Property="Visibility" Value="Collapsed" TargetName="PART_HeaderRow"/>
            </Trigger>
            <Trigger Property="ShowGroupPanel" Value="false">
                <Setter Property="Visibility" Value="Collapsed" TargetName="PART_GroupPanel"/>
            </Trigger>


            <Trigger Property="ComputedVerticalScrollBarVisibility" SourceName="PART_ItemsScrollViewer" Value="Collapsed">
                <Setter Property="Width" TargetName="ScrollBarColumn" Value="0" />
            </Trigger>
            <Trigger Property="ComputedHorizontalScrollBarVisibility" SourceName="PART_ItemsScrollViewer" Value="Collapsed">
                <Setter Property="Height" TargetName="ScrollBarRow" Value="0" />
            </Trigger>
            <Trigger Property="ShowColumnHeaders" Value="false">
                <Setter Property="VerticalScrollBarMargin" TargetName="PART_ItemsScrollViewer">
                    <Setter.Value>
                        <Thickness Left="0" Top="0" Right="0" Bottom="0" />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <Style 
        
        x:Key="{telerik:ThemeResourceKey ThemeType=local:MyCustomTheme, ElementType=grid:GridViewItemsControl}"
        
        TargetType="grid:GridViewItemsControl">
        <Setter Property="Template" Value="{StaticResource GridViewItemsControlTemplate}" />
        <Setter Property="GroupPanelBackground" Value="{StaticResource GridViewGroupPanelOuterBorderbackground}"/>
        <Setter Property="GroupPanelForeground" Value="{StaticResource GridViewGroupPanelTextBlockForeground}" />
        <Setter Property="BorderBrush" Value="{StaticResource GridViewGroupPanelInnerBorderBrush}" />
        <Setter Property="BorderThickness" Value="0,0,1,1" />
        <Setter Property="MinHeight" Value="26" />
    </Style>
    
    
</ResourceDictionary>