<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:bpa="clr-namespace:BPA.UIControl"
                    xmlns:converter="clr-namespace:BPA.UIControl.Converters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/Resources/Default.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="ExpanderDownHeaderStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid>
                        <Border x:Name="border"
                                Padding="{TemplateBinding Padding}"
                                Background="{TemplateBinding Background}">
                            <Border.CornerRadius>
                                <MultiBinding Converter="{StaticResource InsideCornerRadiusConverter}">
                                    <MultiBinding.Bindings>
                                        <Binding Path="BorderThickness" RelativeSource="{RelativeSource AncestorType=Border}" />
                                        <Binding Path="CornerRadius" RelativeSource="{RelativeSource AncestorType=Border}" />
                                    </MultiBinding.Bindings>
                                </MultiBinding>
                            </Border.CornerRadius>
                            <DockPanel>
                                <bpa:Icon x:Name="arrow"
                                          Grid.Column="1"
                                          DockPanel.Dock="{Binding Path=(bpa:ExpanderHelper.ExpandIconDock), RelativeSource={RelativeSource AncestorType=Expander}}"
                                          Foreground="{TemplateBinding Foreground}"
                                          RenderTransformOrigin="0.5 0.5"
                                          Type="{Binding Path=(bpa:ExpanderHelper.ExpandIconType), RelativeSource={RelativeSource AncestorType=Expander}}">
                                    <bpa:Icon.RenderTransform>
                                        <RotateTransform x:Name="arrowAngle" Angle="0" />
                                    </bpa:Icon.RenderTransform>
                                </bpa:Icon>

                                <ContentPresenter Margin="4 0 0 0"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="Center"
                                                  RecognizesAccessKey="True"
                                                  SnapsToDevicePixels="True" />
                            </DockPanel>
                        </Border>

                        <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=Expander}}"
                                         CornerRadius="{Binding CornerRadius, ElementName=border}"
                                         IsActive="{TemplateBinding IsPressed}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=Expander}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowAngle"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="180"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowAngle"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="0"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="ExpanderUpHeaderStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid>
                        <Border x:Name="border"
                                Padding="{TemplateBinding Padding}"
                                Background="{TemplateBinding Background}">
                            <Border.CornerRadius>
                                <MultiBinding Converter="{StaticResource InsideCornerRadiusConverter}">
                                    <MultiBinding.Bindings>
                                        <Binding Path="BorderThickness" RelativeSource="{RelativeSource AncestorType=Border}" />
                                        <Binding Path="CornerRadius" RelativeSource="{RelativeSource AncestorType=Border}" />
                                    </MultiBinding.Bindings>
                                </MultiBinding>
                            </Border.CornerRadius>
                            <DockPanel>
                                <bpa:Icon x:Name="arrow"
                                          Grid.Column="1"
                                          DockPanel.Dock="{Binding Path=(bpa:ExpanderHelper.ExpandIconDock), RelativeSource={RelativeSource AncestorType=Expander}}"
                                          Foreground="{TemplateBinding Foreground}"
                                          RenderTransformOrigin="0.5 0.5"
                                          Type="{Binding Path=(bpa:ExpanderHelper.ExpandIconType), RelativeSource={RelativeSource AncestorType=Expander}}">
                                    <bpa:Icon.RenderTransform>
                                        <RotateTransform x:Name="arrowAngle" Angle="0" />
                                    </bpa:Icon.RenderTransform>
                                </bpa:Icon>

                                <ContentPresenter Margin="4 0 0 0"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="Center"
                                                  RecognizesAccessKey="True"
                                                  SnapsToDevicePixels="True" />
                            </DockPanel>
                        </Border>

                        <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=Expander}}"
                                         CornerRadius="{Binding CornerRadius, ElementName=border}"
                                         IsActive="{TemplateBinding IsPressed}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=Expander}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowAngle"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="0"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowAngle"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="180"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="ExpanderLeftHeaderStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid>
                        <Border x:Name="border"
                                Padding="{TemplateBinding Padding}"
                                Background="{TemplateBinding Background}">
                            <Border.CornerRadius>
                                <MultiBinding Converter="{StaticResource InsideCornerRadiusConverter}">
                                    <MultiBinding.Bindings>
                                        <Binding Path="BorderThickness" RelativeSource="{RelativeSource AncestorType=Border}" />
                                        <Binding Path="CornerRadius" RelativeSource="{RelativeSource AncestorType=Border}" />
                                    </MultiBinding.Bindings>
                                </MultiBinding>
                            </Border.CornerRadius>
                            <DockPanel>
                                <bpa:Icon x:Name="arrow"
                                          Grid.Row="1"
                                          DockPanel.Dock="{Binding Path=(bpa:ExpanderHelper.ExpandIconDock), RelativeSource={RelativeSource AncestorType=Expander}}"
                                          Foreground="{TemplateBinding Foreground}"
                                          RenderTransformOrigin="0.5 0.5"
                                          Type="{Binding Path=(bpa:ExpanderHelper.ExpandIconType), RelativeSource={RelativeSource AncestorType=Expander}}">
                                    <bpa:Icon.RenderTransform>
                                        <RotateTransform x:Name="arrowAngle" Angle="90" />
                                    </bpa:Icon.RenderTransform>
                                </bpa:Icon>

                                <ContentPresenter Margin="0 4 0 0"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  RecognizesAccessKey="True"
                                                  SnapsToDevicePixels="True" />
                            </DockPanel>
                        </Border>
                        <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=Expander}}"
                                         CornerRadius="{Binding CornerRadius, ElementName=border}"
                                         IsActive="{TemplateBinding IsPressed}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=Expander}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowAngle"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="-90"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowAngle"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="90"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="ExpanderRightHeaderStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid>
                        <Border x:Name="border"
                                Padding="{TemplateBinding Padding}"
                                Background="{TemplateBinding Background}">
                            <Border.CornerRadius>
                                <MultiBinding Converter="{StaticResource InsideCornerRadiusConverter}">
                                    <MultiBinding.Bindings>
                                        <Binding Path="BorderThickness" RelativeSource="{RelativeSource AncestorType=Border}" />
                                        <Binding Path="CornerRadius" RelativeSource="{RelativeSource AncestorType=Border}" />
                                    </MultiBinding.Bindings>
                                </MultiBinding>
                            </Border.CornerRadius>
                            <DockPanel>
                                <bpa:Icon x:Name="arrow"
                                          Grid.Row="1"
                                          DockPanel.Dock="{Binding Path=(bpa:ExpanderHelper.ExpandIconDock), RelativeSource={RelativeSource AncestorType=Expander}}"
                                          Foreground="{TemplateBinding Foreground}"
                                          RenderTransformOrigin="0.5 0.5"
                                          Type="{Binding Path=(bpa:ExpanderHelper.ExpandIconType), RelativeSource={RelativeSource AncestorType=Expander}}">
                                    <bpa:Icon.RenderTransform>
                                        <RotateTransform x:Name="arrowAngle" Angle="-90" />
                                    </bpa:Icon.RenderTransform>
                                </bpa:Icon>

                                <ContentPresenter Margin="0 4 0 0"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                  RecognizesAccessKey="True"
                                                  SnapsToDevicePixels="True" />
                            </DockPanel>
                        </Border>
                        <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=Expander}}"
                                         CornerRadius="{Binding CornerRadius, ElementName=border}"
                                         IsActive="{TemplateBinding IsPressed}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=Expander}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowAngle"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="90"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="arrowAngle"
                                                         Storyboard.TargetProperty="Angle"
                                                         To="-90"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="RubyerExpander" TargetType="{x:Type Expander}">
        <Setter Property="Background" Value="{DynamicResource DefaultBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="BorderThickness" Value="{DynamicResource DefaultBorderThickness}" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Padding" Value="5" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Mask}" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{DynamicResource AllContainerCornerRadius}" />
        <Setter Property="bpa:HeaderHelper.Background" Value="{DynamicResource DefaultBackground}" />
        <Setter Property="bpa:HeaderHelper.Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="bpa:HeaderHelper.FontSize" Value="{Binding FontSize, RelativeSource={RelativeSource Self}}" />
        <Setter Property="bpa:HeaderHelper.FontWeight" Value="Normal" />
        <Setter Property="bpa:HeaderHelper.HorizontalAlignment" Value="Left" />
        <Setter Property="bpa:HeaderHelper.VerticalAlignment" Value="Top" />
        <Setter Property="bpa:HeaderHelper.Padding" Value="5" />
        <Setter Property="bpa:ExpanderHelper.ExpandIconType" Value="ArrowDownSLine" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <Border x:Name="border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <DockPanel>
                            <ToggleButton x:Name="HeaderSite"
                                          Style="{StaticResource ExpanderDownHeaderStyle}"
                                          MinWidth="0"
                                          MinHeight="0"
                                          Padding="{Binding Path=(bpa:HeaderHelper.Padding), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                          HorizontalContentAlignment="{Binding Path=(bpa:HeaderHelper.HorizontalAlignment), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                          VerticalContentAlignment="{Binding Path=(bpa:HeaderHelper.VerticalAlignment), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                          Background="{Binding Path=(bpa:HeaderHelper.Background), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                          Content="{TemplateBinding Header}"
                                          ContentTemplate="{TemplateBinding HeaderTemplate}"
                                          ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                          DockPanel.Dock="Top"
                                          FocusVisualStyle="{StaticResource FocusVisual}"
                                          FontFamily="{Binding Path=(bpa:HeaderHelper.FontFamily), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                          FontSize="{Binding Path=(bpa:HeaderHelper.FontSize), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                          FontStretch="{TemplateBinding FontStretch}"
                                          FontStyle="{TemplateBinding FontStyle}"
                                          FontWeight="{Binding Path=(bpa:HeaderHelper.FontWeight), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                          Foreground="{Binding Path=(bpa:HeaderHelper.Foreground), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                          IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
                            <bpa:Transition x:Name="Transition"
                                            IsShow="{TemplateBinding IsExpanded}"
                                            Type="CollapseUp">
                                <ContentPresenter x:Name="ExpandSite"
                                                  Margin="{TemplateBinding Padding}"
                                                  Focusable="false" />
                            </bpa:Transition>
                        </DockPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ExpandSite"
                                                         Storyboard.TargetProperty="Opacity"
                                                         From="0"
                                                         To="1"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseIn" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ExpandSite"
                                                         Storyboard.TargetProperty="Opacity"
                                                         From="1"
                                                         To="0"
                                                         Duration="0:0:0.3">
                                            <DoubleAnimation.EasingFunction>
                                                <CubicEase EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                        <Trigger Property="ExpandDirection" Value="Right">
                            <Setter TargetName="ExpandSite" Property="DockPanel.Dock" Value="Right" />
                            <Setter TargetName="HeaderSite" Property="DockPanel.Dock" Value="Left" />
                            <Setter TargetName="HeaderSite" Property="Style" Value="{StaticResource ExpanderRightHeaderStyle}" />
                            <Setter TargetName="Transition" Property="Type" Value="CollapseLeft" />
                            <Setter Property="bpa:ExpanderHelper.ExpandIconDock" Value="Bottom" />
                        </Trigger>
                        <Trigger Property="ExpandDirection" Value="Up">
                            <Setter TargetName="ExpandSite" Property="DockPanel.Dock" Value="Top" />
                            <Setter TargetName="HeaderSite" Property="DockPanel.Dock" Value="Bottom" />
                            <Setter TargetName="HeaderSite" Property="Style" Value="{StaticResource ExpanderUpHeaderStyle}" />
                        </Trigger>
                        <Trigger Property="ExpandDirection" Value="Left">
                            <Setter TargetName="ExpandSite" Property="DockPanel.Dock" Value="Left" />
                            <Setter TargetName="HeaderSite" Property="DockPanel.Dock" Value="Right" />
                            <Setter TargetName="HeaderSite" Property="Style" Value="{StaticResource ExpanderLeftHeaderStyle}" />
                            <Setter TargetName="Transition" Property="Type" Value="CollapseLeft" />
                            <Setter Property="bpa:ExpanderHelper.ExpandIconDock" Value="Bottom" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="border" Property="Opacity" Value="{DynamicResource UnenableOpcity}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>