<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"
>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Resources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate x:Key="GridViewExpanderToggleButtonTemplate" TargetType="ToggleButton">

        <ControlTemplate.Resources>
            <Storyboard x:Key="Expand">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ExpanderButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.12" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="Collapse">
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ExpanderButton" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
                    <SplineDoubleKeyFrame KeyTime="00:00:00.12" Value="180"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
        </ControlTemplate.Resources>

        <Grid>

            <Border x:Name="BackgroundEllipse" VerticalAlignment="Top" HorizontalAlignment="Left" Width="24">

                <Path x:Name="ExpanderButton" Margin="9,9,8,10" Fill="{StaticResource GridViewExpanderButtonFill}" Stroke="{x:Null}" Data="M3,0 L4,0 4,0.99999972 5,0.99999993 5,1.9999999 6,1.9999999 6,2.9999999 7,2.9999999 7,3.9999999 7,4.9999999 6,4.9999999 5,4.9999999 5,3.9999999 4,3.9999999 4,2.9999999 3,2.9999999 3,3.9999999 2,3.9999999 2,4.9999999 1,4.9999999 0,4.9999999 0,3.9999999 0,2.9999999 1,2.9999999&#xa;1,1.9999999 2,1.9999999 2,0.99999972 3,0.99999972 z" RenderTransformOrigin="0.5,0.5">
                    <Path.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="1" ScaleY="1"/>
                            <SkewTransform AngleX="0" AngleY="0"/>
                            <RotateTransform Angle="0"/>
                            <TranslateTransform X="0" Y="0"/>
                        </TransformGroup>
                    </Path.RenderTransform>
                </Path>
            </Border>


        </Grid>


        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard Storyboard="{StaticResource Expand}" />
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard Storyboard="{StaticResource Collapse}" />
                </Trigger.ExitActions>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="BackgroundEllipse" Property="Opacity" Value="1" />
            </Trigger>
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <ControlTemplate x:Key="GridViewExpanderTemplate" TargetType="grid:GridViewExpander">
        <Grid x:Name="PART_GroupExpanderGrid" HorizontalAlignment="Stretch" 
			  Background="{StaticResource GridViewExpanderBackground}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition x:Name="PART_HeaderRow" />
                <RowDefinition x:Name="ContentRow" />
            </Grid.RowDefinitions>
            <grid:HorizontalScrollPanel HorizontalScrollEnabled="False" x:Name="PART_HeaderScroller" Grid.Column="1" HorizontalAlignment="Stretch" >
                <Border x:Name="PART_GroupExpanderBorder" Background="{TemplateBinding Background}" 
						BorderBrush="{TemplateBinding BorderBrush}"
						
					SnapsToDevicePixels="True"
					 >
                    <Grid Name="PART_HeaderGrid" MinHeight="{TemplateBinding MinHeight}">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <grid:IndentPresenter IndentLevel="{Binding Level}" Grid.Column="0"  />

                        <ToggleButton x:Name="HeaderButton" Background="{TemplateBinding Background}"  OverridesDefaultStyle="False" Template="{StaticResource GridViewExpanderToggleButtonTemplate}" Grid.Column="1" />


                        <ContentPresenter Grid.Column="2" ContentSource="Header" RecognizesAccessKey="True" VerticalAlignment="Center" 
											  Margin="3"
											  TextBlock.FontWeight="{TemplateBinding FontWeight}" 
											  TextBlock.FontSize="{TemplateBinding FontSize}"
											  TextBlock.FontFamily="{TemplateBinding FontFamily}"
											  TextBlock.Foreground="{TemplateBinding Foreground}"/>



                        <grid:AggregateResultsList Grid.Column="3" HorizontalAlignment="Left" VerticalAlignment="Center" >
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <grid:GridViewAggregateResultCell AggregateResult="{Binding}"  />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </grid:AggregateResultsList>
                        <Rectangle Grid.Column="4" Height="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" 
									Fill="{StaticResource GridViewExpanderLineFill}" />
                    </Grid>
                </Border>
            </grid:HorizontalScrollPanel>

            <Border Grid.Column="0" Grid.ColumnSpan="2" Name="Content" Background="{TemplateBinding IndentBackground}" SnapsToDevicePixels="True" Grid.Row="1" CornerRadius="0,0,2,2">
                <ContentPresenter />
            </Border>

            <grid:IndicatorPresenter x:Name="PART_IndicatorPresenter" Visibility="{TemplateBinding RowIndicatorVisibility}" VerticalAlignment="Stretch" />

        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="IsExpanded" Value="false">
                <Setter Property="Visibility" TargetName="Content" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundColor}" />
            </Trigger>
        </ControlTemplate.Triggers>

    </ControlTemplate>

    <Style 
        
        x:Key="{telerik:ThemeResourceKey ThemeType=local:MyCustomTheme, ElementType=grid:GridViewExpander}"
        
        TargetType="grid:GridViewExpander">
        <Setter Property="grid:GridViewExpander.Template" Value="{StaticResource GridViewExpanderTemplate}" />
        <Setter Property="MinHeight" Value="24" />
        <Setter Property="Background" Value="{StaticResource GridViewRowBackground}" />
        <Setter Property="BorderBrush" Value="{StaticResource GridViewHeaderCellBorderBrush}" />
        <Setter Property="FontSize" Value="11" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="FontFamily" Value="Segoe UI" />
        <Setter Property="Foreground" Value="{StaticResource GridViewExpanderForeground}" />
        <Setter Property="IndentBackground" Value="{StaticResource GridViewRowBackground}" />
    </Style>

</ResourceDictionary>