<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:system="clr-namespace:System;assembly=mscorlib">

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

    <Style x:Key="RubyerScrollBarArrowButton"
           BasedOn="{StaticResource TextRepeatButton}"
           TargetType="{x:Type RepeatButton}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Cursor" Value="Arrow" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="FontSize" Value="{Binding Path=(bpa:ScrollViewerHelper.ScrollBarSize), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ControlHelper.MaskOpacity" Value="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
    </Style>

    <Style x:Key="RubyerScrollBarPageButton" TargetType="{x:Type RepeatButton}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="Transparent" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="RubyerScrollBarThumb" TargetType="{x:Type Thumb}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Grid Margin="1">
                        <Border x:Name="border"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="0"
                                CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=ScrollBar}}" />
                        <bpa:ControlMask Background="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=ScrollBar}}"
                                         CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=ScrollBar}}"
                                         IsActive="{TemplateBinding IsDragging}"
                                         MaskOpacity="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=ScrollBar}}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="RubyerVerticalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid x:Name="root">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.Tag>
                <system:Double>0.5</system:Double>
            </Grid.Tag>
            <Grid.Width>
                <MultiBinding Converter="{StaticResource MathMultiplyConverter}">
                    <Binding Path="(rubyer:ScrollViewerHelper.ScrollBarSize)" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                    <Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
                </MultiBinding>
            </Grid.Width>

            <Border Grid.RowSpan="3"
                    Background="{TemplateBinding Background}"
                    CornerRadius="{DynamicResource AllControlCornerRadius}" />

            <RepeatButton x:Name="upButton"
                          Style="{StaticResource RubyerScrollBarArrowButton}"
                          Grid.Row="0"
                          Width="{TemplateBinding Width}"
                          Height="{TemplateBinding Width}"
                          Command="ScrollBar.LineUpCommand"
                          Foreground="{Binding Path=(bpa:ScrollViewerHelper.ArrowIconBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                          Visibility="Collapsed">
                <bpa:Icon Type="ArrowUpSLine" />
            </RepeatButton>

            <Track x:Name="PART_Track"
                   Grid.Row="1"
                   IsDirectionReversed="True">
                <Track.DecreaseRepeatButton>
                    <RepeatButton Style="{StaticResource RubyerScrollBarPageButton}" Command="ScrollBar.PageUpCommand" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb Style="{StaticResource RubyerScrollBarThumb}" Background="{Binding Path=(bpa:ScrollViewerHelper.ScrollBarForeground), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton Style="{StaticResource RubyerScrollBarPageButton}" Command="ScrollBar.PageDownCommand" />
                </Track.IncreaseRepeatButton>
            </Track>

            <RepeatButton x:Name="downButton"
                          Style="{StaticResource RubyerScrollBarArrowButton}"
                          Grid.Row="2"
                          Width="{TemplateBinding Width}"
                          Height="{TemplateBinding Width}"
                          Command="ScrollBar.LineDownCommand"
                          Foreground="{Binding Path=(bpa:ScrollViewerHelper.ArrowIconBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                          Visibility="Collapsed">
                <bpa:Icon Type="ArrowDownSLine" />
            </RepeatButton>
        </Grid>
        <ControlTemplate.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" />
                    <Condition Binding="{Binding Path=(bpa:ScrollViewerHelper.ShowArrowButton), RelativeSource={RelativeSource Self}}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter TargetName="upButton" Property="Visibility" Value="Visible" />
                <Setter TargetName="downButton" Property="Visibility" Value="Visible" />
            </MultiDataTrigger>

            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="bpa:ScrollViewerHelper.ShowArrowButton" Value="True" />
                    <Condition Property="bpa:ScrollViewerHelper.IsDynamicBarSize" Value="False" />
                </MultiTrigger.Conditions>
                <Setter TargetName="upButton" Property="Visibility" Value="Visible" />
                <Setter TargetName="downButton" Property="Visibility" Value="Visible" />
            </MultiTrigger>

            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Orientation" Value="Vertical" />
                    <Condition Property="IsMouseOver" Value="True" />
                    <Condition Property="bpa:ScrollViewerHelper.IsDynamicBarSize" Value="True" />
                </MultiTrigger.Conditions>
                <MultiTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="root"
                                             Storyboard.TargetProperty="Tag"
                                             To="1"
                                             Duration="0:0:0.3">
                                <DoubleAnimation.EasingFunction>
                                    <CubicEase EasingMode="EaseOut" />
                                </DoubleAnimation.EasingFunction>
                            </DoubleAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </MultiTrigger.EnterActions>
                <MultiTrigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="root"
                                             Storyboard.TargetProperty="Tag"
                                             To="0.5"
                                             Duration="0:0:0.3">
                                <DoubleAnimation.EasingFunction>
                                    <CubicEase EasingMode="EaseOut" />
                                </DoubleAnimation.EasingFunction>
                            </DoubleAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </MultiTrigger.ExitActions>
            </MultiTrigger>
            <Trigger Property="bpa:ScrollViewerHelper.IsDynamicBarSize" Value="False">
                <Setter TargetName="root" Property="Tag" Value="1" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="RubyerHorizontalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid x:Name="root">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.Tag>
                <system:Double>0.5</system:Double>
            </Grid.Tag>
            <Grid.Height>
                <MultiBinding Converter="{StaticResource MathMultiplyConverter}">
                    <Binding Path="(rubyer:ScrollViewerHelper.ScrollBarSize)" RelativeSource="{RelativeSource Mode=TemplatedParent}" />
                    <Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
                </MultiBinding>
            </Grid.Height>

            <Border Grid.ColumnSpan="3"
                    Background="{TemplateBinding Background}"
                    CornerRadius="{DynamicResource AllControlCornerRadius}" />

            <RepeatButton x:Name="leftButton"
                          Style="{StaticResource RubyerScrollBarArrowButton}"
                          Grid.Column="0"
                          Width="{TemplateBinding Height}"
                          Height="{TemplateBinding Height}"
                          Command="ScrollBar.LineLeftCommand"
                          Foreground="{Binding Path=(bpa:ScrollViewerHelper.ArrowIconBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                          Visibility="Collapsed">
                <bpa:Icon Type="ArrowLeftSLine" />
            </RepeatButton>

            <Track x:Name="PART_Track"
                   Grid.Column="1"
                   IsDirectionReversed="False">
                <Track.DecreaseRepeatButton>
                    <RepeatButton Style="{StaticResource RubyerScrollBarPageButton}" Command="ScrollBar.PageLeftCommand" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb Style="{StaticResource RubyerScrollBarThumb}" Background="{Binding Path=(bpa:ScrollViewerHelper.ScrollBarForeground), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton Style="{StaticResource RubyerScrollBarPageButton}" Command="ScrollBar.PageRightCommand" />
                </Track.IncreaseRepeatButton>
            </Track>

            <RepeatButton x:Name="rightButton"
                          Style="{StaticResource RubyerScrollBarArrowButton}"
                          Grid.Column="2"
                          Width="{TemplateBinding Height}"
                          Height="{TemplateBinding Height}"
                          Command="ScrollBar.LineRightCommand"
                          Cursor="Arrow"
                          Foreground="{Binding Path=(bpa:ScrollViewerHelper.ArrowIconBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                          Visibility="Collapsed">
                <bpa:Icon Type="ArrowRightSLine" />
            </RepeatButton>
        </Grid>
        <ControlTemplate.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" />
                    <Condition Binding="{Binding Path=(bpa:ScrollViewerHelper.ShowArrowButton), RelativeSource={RelativeSource Self}}" Value="True" />
                </MultiDataTrigger.Conditions>
                <Setter TargetName="leftButton" Property="Visibility" Value="Visible" />
                <Setter TargetName="rightButton" Property="Visibility" Value="Visible" />
            </MultiDataTrigger>

            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="bpa:ScrollViewerHelper.ShowArrowButton" Value="True" />
                    <Condition Property="bpa:ScrollViewerHelper.IsDynamicBarSize" Value="False" />
                </MultiTrigger.Conditions>
                <Setter TargetName="leftButton" Property="Visibility" Value="Visible" />
                <Setter TargetName="rightButton" Property="Visibility" Value="Visible" />
            </MultiTrigger>

            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Orientation" Value="Horizontal" />
                    <Condition Property="IsMouseOver" Value="True" />
                    <Condition Property="bpa:ScrollViewerHelper.IsDynamicBarSize" Value="True" />
                </MultiTrigger.Conditions>
                <MultiTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="root"
                                             Storyboard.TargetProperty="Tag"
                                             To="1"
                                             Duration="0:0:0.3">
                                <DoubleAnimation.EasingFunction>
                                    <CubicEase EasingMode="EaseOut" />
                                </DoubleAnimation.EasingFunction>
                            </DoubleAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </MultiTrigger.EnterActions>
                <MultiTrigger.ExitActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="root"
                                             Storyboard.TargetProperty="Tag"
                                             To="0.5"
                                             Duration="0:0:0.3">
                                <DoubleAnimation.EasingFunction>
                                    <CubicEase EasingMode="EaseOut" />
                                </DoubleAnimation.EasingFunction>
                            </DoubleAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </MultiTrigger.ExitActions>
            </MultiTrigger>
            <Trigger Property="bpa:ScrollViewerHelper.IsDynamicBarSize" Value="False">
                <Setter TargetName="root" Property="Tag" Value="1" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="RubyerScrollBar" TargetType="{x:Type ScrollBar}">
        <Setter Property="Background" Value="{Binding Path=(bpa:ScrollViewerHelper.ScrollBarBackground), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ControlHelper.MaskOpacity" Value="{Binding Path=(bpa:ControlHelper.MaskOpacity), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{Binding Path=(bpa:ControlHelper.FocusedBrush), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ScrollViewerHelper.ScrollBarForeground" Value="{Binding Path=(bpa:ScrollViewerHelper.ScrollBarForeground), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ScrollViewerHelper.ShowArrowButton" Value="{Binding Path=(bpa:ScrollViewerHelper.ShowArrowButton), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ScrollViewerHelper.ArrowIconBrush" Value="{Binding Path=(bpa:ScrollViewerHelper.ArrowIconBrush), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ScrollViewerHelper.ScrollBarSize" Value="{Binding Path=(bpa:ScrollViewerHelper.ScrollBarSize), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Setter Property="bpa:ScrollViewerHelper.IsDynamicBarSize" Value="{Binding Path=(bpa:ScrollViewerHelper.IsDynamicBarSize), RelativeSource={RelativeSource AncestorType=ScrollViewer}}" />
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="Template" Value="{StaticResource RubyerHorizontalScrollBar}" />
                <Setter Property="Width" Value="Auto" />
            </Trigger>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Height" Value="Auto" />
                <Setter Property="Template" Value="{StaticResource RubyerVerticalScrollBar}" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>