<!--
    This Source Code Form is subject to the terms of the MIT License.
    If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
    Copyright (C) Leszek Pomianowski and WPF UI Contributors.
    All Rights Reserved.

    Based on Microsoft XAML for Win UI
    Copyright (c) Microsoft Corporation. All Rights Reserved.
-->

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system="clr-namespace:System;assembly=System.Runtime"
    xmlns:fluentcontrols="clr-namespace:Fluent.Controls"
    >

    <Thickness x:Key="ExpanderPadding">11,11,11,11</Thickness>
    <Thickness x:Key="ExpanderBorderThemeThickness">1</Thickness>
    <system:Double x:Key="ExpanderChevronSize">12.0</system:Double>
    <fluentcontrols:AnimationFactorToValueConverter x:Key="AnimationFactorToValueConverter" />
    <system:String x:Key="ExpanderChevronUpGlyph">&#xE70E;</system:String>
    <system:String x:Key="ExpanderChevronDownGlyph">&#xE70D;</system:String>
    <system:String x:Key="ExpanderChevronLeftGlyph">&#xE76B;</system:String>
    <system:String x:Key="ExpanderChevronRightGlyph">&#xE76C;</system:String>

    <ControlTemplate x:Key="DefaultExpanderToggleButtonDownStyle" TargetType="{x:Type ToggleButton}">
        <Grid Margin="{TemplateBinding Padding}" Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <ContentPresenter
                x:Name="ContentPresenter"
                Grid.Column="0"
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                Content="{TemplateBinding Content}"
                TextElement.FontSize="{TemplateBinding FontSize}" />
            <Grid
                x:Name="ChevronGrid"
                Grid.Column="1"
                Margin="0"
                VerticalAlignment="Center"
                Background="Transparent"
                RenderTransformOrigin="0.5, 0.5">
                <Grid.RenderTransform>
                    <RotateTransform Angle="0" />
                </Grid.RenderTransform>
                <TextBlock
                    x:Name="ControlChevronIcon"
                    FontSize="{StaticResource ExpanderChevronSize}"
                    Foreground="{TemplateBinding Foreground}"
                    FontFamily="{DynamicResource SymbolThemeFontFamily}"
                    HorizontalAlignment="Center"
                    Text="{StaticResource ExpanderChevronDownGlyph}" />
            </Grid>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ChevronGrid"
                                Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)"
                                To="180"
                                Duration="00:00:00.167" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ChevronGrid"
                                Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)"
                                To="0"
                                Duration="00:00:00.167" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.ExitActions>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="DefaultExpanderToggleButtonUpStyle" TargetType="{x:Type ToggleButton}">
        <Grid Margin="{TemplateBinding Padding}" Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <ContentPresenter
                x:Name="ContentPresenter"
                Grid.Column="0"
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                Content="{TemplateBinding Content}"
                TextElement.FontSize="{TemplateBinding FontSize}" />
            <Grid
                x:Name="ChevronGrid"
                Grid.Column="1"
                Margin="0"
                VerticalAlignment="Center"
                Background="Transparent"
                RenderTransformOrigin="0.5, 0.5">
                <Grid.RenderTransform>
                    <RotateTransform Angle="0" />
                </Grid.RenderTransform>
                <TextBlock
                    x:Name="ControlChevronIcon"
                    FontSize="{StaticResource ExpanderChevronSize}"
                    Foreground="{TemplateBinding Foreground}"
                    FontFamily="{DynamicResource SymbolThemeFontFamily}"
                    HorizontalAlignment="Center"
                    Text="{StaticResource ExpanderChevronUpGlyph}" />
            </Grid>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ChevronGrid"
                                Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)"
                                To="180"
                                Duration="00:00:00.167" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ChevronGrid"
                                Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)"
                                To="0"
                                Duration="00:00:00.167" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.ExitActions>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="DefaultExpanderToggleButtonLeftStyle" TargetType="{x:Type ToggleButton}">
        <Grid Margin="{TemplateBinding Padding}" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ContentPresenter
                x:Name="ContentPresenter"
                Grid.Row="0"
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                Content="{TemplateBinding Content}"
                TextElement.FontSize="{TemplateBinding FontSize}" />
            <Grid
                x:Name="ChevronGrid"
                Grid.Row="1"
                Margin="0"
                VerticalAlignment="Center"
                Background="Transparent"
                RenderTransformOrigin="0.5, 0.5">
                <Grid.RenderTransform>
                    <RotateTransform Angle="0" />
                </Grid.RenderTransform>
                    <TextBlock
                        x:Name="ControlChevronIcon"
                        FontSize="{StaticResource ExpanderChevronSize}"
                        Foreground="{TemplateBinding Foreground}"
                        FontFamily="{DynamicResource SymbolThemeFontFamily}"
                        HorizontalAlignment="Center"
                        Text="{StaticResource ExpanderChevronLeftGlyph}" />
            </Grid>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ChevronGrid"
                                Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)"
                                To="180"
                                Duration="00:00:00.167" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ChevronGrid"
                                Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)"
                                To="0"
                                Duration="00:00:00.167" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.ExitActions>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="DefaultExpanderToggleButtonRightStyle" TargetType="{x:Type ToggleButton}">
        <Grid Margin="{TemplateBinding Padding}" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ContentPresenter
                x:Name="ContentPresenter"
                Grid.Row="0"
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                Content="{TemplateBinding Content}"
                TextElement.FontSize="{TemplateBinding FontSize}" />
            <Grid
                x:Name="ChevronGrid"
                Grid.Row="1"
                Margin="0"
                VerticalAlignment="Center"
                Background="Transparent"
                RenderTransformOrigin="0.5, 0.5">
                <Grid.RenderTransform>
                    <RotateTransform Angle="0" />
                </Grid.RenderTransform>
                <TextBlock
                    x:Name="ControlChevronIcon"
                    FontSize="{StaticResource ExpanderChevronSize}"
                    Foreground="{TemplateBinding Foreground}"
                    FontFamily="{DynamicResource SymbolThemeFontFamily}"
                    HorizontalAlignment="Center"
                    Text="{StaticResource ExpanderChevronRightGlyph}" />
            </Grid>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ChevronGrid"
                                Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)"
                                To="180"
                                Duration="00:00:00.167" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
                <Trigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetName="ChevronGrid"
                                Storyboard.TargetProperty="(Grid.RenderTransform).(RotateTransform.Angle)"
                                To="0"
                                Duration="00:00:00.167" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.ExitActions>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="DefaultExpanderStyle" TargetType="{x:Type Expander}">
        <Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
        <Setter Property="Background" Value="{DynamicResource ExpanderHeaderBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource ExpanderHeaderForeground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ExpanderHeaderBorderBrush}" />
        <Setter Property="BorderThickness" Value="{StaticResource ExpanderBorderThemeThickness}" />
        <Setter Property="Padding" Value="{StaticResource ExpanderPadding}" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="FontWeight" Value="Normal" />
        <Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
        <Setter Property="IsExpanded" Value="False" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <DockPanel>
                        <Border x:Name="ToggleButtonBorder"
                                DockPanel.Dock="Top"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{TemplateBinding Border.CornerRadius}">
                            <ToggleButton
                                        x:Name="HeaderSite"
                                        AutomationProperties.Name="{TemplateBinding AutomationProperties.Name}"
                                        Margin="0"
                                        Padding="{TemplateBinding Padding}"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                        HorizontalContentAlignment="Stretch"
                                        VerticalContentAlignment="Center"
                                        Content="{TemplateBinding Header}"
                                        ContentTemplate="{TemplateBinding HeaderTemplate}"
                                        ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                        FontFamily="{TemplateBinding FontFamily}"
                                        FontSize="{TemplateBinding FontSize}"
                                        FontStyle="{TemplateBinding FontStyle}"
                                        FontStretch="{TemplateBinding FontStretch}"
                                        FontWeight="{TemplateBinding FontWeight}"
                                        Foreground="{TemplateBinding Foreground}"
                                        IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                        IsEnabled="{TemplateBinding IsEnabled}"
                                        OverridesDefaultStyle="True"
                                        Template="{StaticResource DefaultExpanderToggleButtonDownStyle}"
                                        FocusVisualStyle="{DynamicResource DefaultControlFocusVisualStyle}"/>
                        </Border>

                        <Grid x:Name="ContentPresenterGrid" DockPanel.Dock="Bottom" ClipToBounds="True">
                            <!-- Dummy border to store Animation factor for expander -->
                            <Border x:Name="AnimationFactorBorder" Width="0" Visibility="Collapsed" />
                            <Border x:Name="ContentPresenterBorder"
                                    Background="{DynamicResource ExpanderContentBackground}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="1,0,1,1"
                                    CornerRadius="0,0,4,4"
                                    Visibility="Collapsed">
                                <ContentPresenter x:Name="ContentPresenter"
                                                  Margin="{TemplateBinding Padding}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  Content="{TemplateBinding Content}" />
                                <Border.Resources>
                                    <TranslateTransform x:Key="HeightAnimationNegative">
                                        <TranslateTransform.Y>
                                            <MultiBinding Converter="{StaticResource AnimationFactorToValueConverter}" ConverterParameter="negative">
                                                <Binding ElementName="ContentPresenterBorder" Path="ActualHeight" />
                                                <Binding ElementName="AnimationFactorBorder" Path="Width" />
                                            </MultiBinding>
                                        </TranslateTransform.Y>
                                    </TranslateTransform>
                                    <TranslateTransform x:Key="WidthAnimationNegative">
                                        <TranslateTransform.X>
                                            <MultiBinding Converter="{StaticResource AnimationFactorToValueConverter}" ConverterParameter="negative">
                                                <Binding ElementName="ContentPresenterBorder" Path="ActualWidth" />
                                                <Binding ElementName="AnimationFactorBorder" Path="Width" />
                                            </MultiBinding>
                                        </TranslateTransform.X>
                                    </TranslateTransform>
                                    <TranslateTransform x:Key="HeightAnimationPositive">
                                        <TranslateTransform.Y>
                                            <MultiBinding Converter="{StaticResource AnimationFactorToValueConverter}" ConverterParameter="positive">
                                                <Binding ElementName="ContentPresenterBorder" Path="ActualHeight" />
                                                <Binding ElementName="AnimationFactorBorder" Path="Width" />
                                            </MultiBinding>
                                        </TranslateTransform.Y>
                                    </TranslateTransform>
                                    <TranslateTransform x:Key="WidthAnimationPositive">
                                        <TranslateTransform.X>
                                            <MultiBinding Converter="{StaticResource AnimationFactorToValueConverter}" ConverterParameter="positive">
                                                <Binding ElementName="ContentPresenterBorder" Path="ActualWidth" />
                                                <Binding ElementName="AnimationFactorBorder" Path="Width" />
                                            </MultiBinding>
                                        </TranslateTransform.X>
                                    </TranslateTransform>
                                </Border.Resources>
                            </Border>
                        </Grid>
                    </DockPanel>

                    <ControlTemplate.Triggers>
                        <!-- Down Expansion Animations -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsExpanded" Value="True" />
                                <Condition Property="ExpandDirection" Value="Down" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ContentPresenterBorder" Property="Visibility" Value="Visible" />
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterBorder" Storyboard.TargetProperty="(Border.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimationFactorBorder" Storyboard.TargetProperty="Width">
                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="1.0" />
                                            <SplineDoubleKeyFrame
                                                KeySpline="0.0, 0.0, 0.0, 1.0"
                                                KeyTime="0:0:0.333"
                                                Value="0.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterBorder" Storyboard.TargetProperty="(Border.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.2" Value="{x:Static Visibility.Collapsed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimationFactorBorder" Storyboard.TargetProperty="Width">
                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="0.0" />
                                            <SplineDoubleKeyFrame
                                                KeySpline="1.0, 1.0, 0.0, 1.0"
                                                KeyTime="0:0:0.333"
                                                Value="1.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>
                        
                        <!-- Up Expansion Animations -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsExpanded" Value="True" />
                                <Condition Property="ExpandDirection" Value="Up" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ToggleButtonBorder" Property="CornerRadius" Value="0,0,4,4" />
                            <Setter TargetName="ContentPresenterBorder" Property="BorderThickness" Value="1,1,1,0" />
                            <Setter TargetName="ContentPresenterBorder" Property="CornerRadius" Value="4,4,0,0" />
                            <Setter TargetName="ContentPresenterBorder" Property="Visibility" Value="Visible" />
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterBorder" Storyboard.TargetProperty="(Border.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimationFactorBorder" Storyboard.TargetProperty="Width">
                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="1.0" />
                                            <SplineDoubleKeyFrame
                                                KeySpline="0.0, 0.0, 0.0, 1.0"
                                                KeyTime="0:0:0.333"
                                                Value="0.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterBorder" Storyboard.TargetProperty="(Border.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.2" Value="{x:Static Visibility.Collapsed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimationFactorBorder" Storyboard.TargetProperty="Width">
                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="0.0" />
                                            <SplineDoubleKeyFrame
                                                KeySpline="1.0, 1.0, 0.0, 1.0"
                                                KeyTime="0:0:0.333"
                                                Value="1.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>

                        <!-- Left Expansion Animations -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsExpanded" Value="True" />
                                <Condition Property="ExpandDirection" Value="Left" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ToggleButtonBorder" Property="CornerRadius" Value="0,4,4,0" />
                            <Setter TargetName="ContentPresenterBorder" Property="BorderThickness" Value="1,1,0,1" />
                            <Setter TargetName="ContentPresenterBorder" Property="CornerRadius" Value="4,0,0,4" />
                            <Setter TargetName="ContentPresenterBorder" Property="Visibility" Value="Visible" />
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterBorder" Storyboard.TargetProperty="(Border.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimationFactorBorder" Storyboard.TargetProperty="Width">
                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="1.0" />
                                            <SplineDoubleKeyFrame
                                                KeySpline="0.0, 0.0, 0.0, 1.0"
                                                KeyTime="0:0:0.333"
                                                Value="0.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterBorder" Storyboard.TargetProperty="(Border.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.2" Value="{x:Static Visibility.Collapsed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimationFactorBorder" Storyboard.TargetProperty="Width">
                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="0.0" />
                                            <SplineDoubleKeyFrame
                                                KeySpline="1.0, 1.0, 0.0, 1.0"
                                                KeyTime="0:0:0.333"
                                                Value="1.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>

                        <!-- Right Expansion Animations -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsExpanded" Value="True" />
                                <Condition Property="ExpandDirection" Value="Right" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="ToggleButtonBorder" Property="CornerRadius" Value="4,0,0,4" />
                            <Setter TargetName="ContentPresenterBorder" Property="BorderThickness" Value="0,1,1,1" />
                            <Setter TargetName="ContentPresenterBorder" Property="CornerRadius" Value="0,4,4,0" />
                            <Setter TargetName="ContentPresenterBorder" Property="Visibility" Value="Visible" />
                            <MultiTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterBorder" Storyboard.TargetProperty="(Border.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimationFactorBorder" Storyboard.TargetProperty="Width">
                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="1.0" />
                                            <SplineDoubleKeyFrame
                                                    KeySpline="0.0, 0.0, 0.0, 1.0"
                                                    KeyTime="0:0:0.333"
                                                    Value="0.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.EnterActions>
                            <MultiTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterBorder" Storyboard.TargetProperty="(Border.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.2" Value="{x:Static Visibility.Collapsed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="AnimationFactorBorder" Storyboard.TargetProperty="Width">
                                            <DiscreteDoubleKeyFrame KeyTime="0" Value="0.0" />
                                            <SplineDoubleKeyFrame
                                                    KeySpline="1.0, 1.0, 0.0, 1.0"
                                                    KeyTime="0:0:0.333"
                                                    Value="1.0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiTrigger.ExitActions>
                        </MultiTrigger>

                        <Trigger Property="ExpandDirection"
                                 Value="Right">
                            <Setter Property="DockPanel.Dock"
                                    Value="Right"
                                    TargetName="ContentPresenterGrid"/>
                            <Setter Property="DockPanel.Dock"
                                    Value="Left"
                                    TargetName="ToggleButtonBorder"/>
                            <Setter Property="Template"
                                    Value="{StaticResource DefaultExpanderToggleButtonRightStyle}"
                                    TargetName="HeaderSite"/>
                            <Setter Property="RenderTransform"
                                    Value="{DynamicResource WidthAnimationNegative}"
                                    TargetName="ContentPresenterBorder" />
                        </Trigger>

                        <Trigger Property="ExpandDirection"
                                 Value="Up">
                            <Setter Property="DockPanel.Dock"
                                    Value="Top"
                                    TargetName="ContentPresenterGrid"/>
                            <Setter Property="DockPanel.Dock"
                                    Value="Bottom"
                                    TargetName="ToggleButtonBorder"/>
                            <Setter Property="Template"
                                    Value="{StaticResource DefaultExpanderToggleButtonUpStyle}"
                                    TargetName="HeaderSite"/>
                            <Setter Property="RenderTransform"
                                    Value="{DynamicResource HeightAnimationPositive}"
                                    TargetName="ContentPresenterBorder" />
                        </Trigger>

                        <Trigger Property="ExpandDirection"
                                 Value="Down">
                            <Setter Property="RenderTransform"
                                    Value="{DynamicResource HeightAnimationNegative}"
                                    TargetName="ContentPresenterBorder" />
                        </Trigger>

                        <Trigger Property="ExpandDirection"
                                 Value="Left">
                            <Setter Property="DockPanel.Dock"
                                    Value="Left"
                                    TargetName="ContentPresenterGrid"/>
                            <Setter Property="DockPanel.Dock"
                                    Value="Right"
                                    TargetName="ToggleButtonBorder"/>
                            <Setter Property="Template"
                                    Value="{StaticResource DefaultExpanderToggleButtonLeftStyle}"
                                    TargetName="HeaderSite"/>
                            <Setter Property="RenderTransform"
                                    Value="{DynamicResource WidthAnimationPositive}"
                                    TargetName="ContentPresenterBorder" />
                        </Trigger>

                        <Trigger Property="IsEnabled"
                                 Value="False">
                            <Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource ExpanderHeaderDisabledForeground}" />
                            <Setter TargetName="HeaderSite" Property="Foreground" Value="{DynamicResource ExpanderHeaderDisabledForeground}" />
                            <Setter TargetName="HeaderSite" Property="BorderBrush" Value="{DynamicResource ExpanderHeaderDisabledBorderBrush}" />
                        </Trigger>

                        <Trigger SourceName="HeaderSite" Property="IsMouseOver" Value="True">
                            <Setter TargetName="HeaderSite" Property="BorderBrush" Value="{DynamicResource ExpanderHeaderBorderPointerOverBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style BasedOn="{StaticResource DefaultExpanderStyle}" TargetType="{x:Type Expander}" />

</ResourceDictionary>
