<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
    xmlns:System="clr-namespace:System;assembly=mscorlib"
    xmlns:po="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options">

    <Storyboard x:Key="MetroScrollBarThumbMouseOverStoryboard" po:Freeze="True">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="MouseOverRectangle" Storyboard.TargetProperty="(UIElement.Opacity)">
            <EasingDoubleKeyFrame KeyTime="0:0:0.15" Value="0.6" />
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="MetroScrollBarThumbPressedStoryboard" po:Freeze="True">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="PressedRectangle" Storyboard.TargetProperty="(UIElement.Opacity)">
            <EasingDoubleKeyFrame KeyTime="0:0:0.15" Value="0.8" />
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

    <Style x:Key="MetroScrollBarRepeatButtonSmallStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Height" Value="{DynamicResource VerticalScrollBarRepeatButtonHeight}" />
        <Setter Property="HorizontalAlignment" Value="Center" />
        <Setter Property="Interval" Value="50" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Margin" Value="1" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Grid
                        Width="{TemplateBinding Width}"
                        Height="{TemplateBinding Height}"
                        Background="{TemplateBinding Background}">
                        <Viewbox
                            x:Name="ArrowBox"
                            Margin="{TemplateBinding Margin}"
                            SnapsToDevicePixels="True"
                            Stretch="Uniform"
                            UseLayoutRounding="True">
                            <Path
                                x:Name="Arrow"
                                Width="256"
                                Height="256"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Data="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content, Mode=OneWay}"
                                Fill="{DynamicResource GrayBrush3}"
                                Stretch="Uniform" />
                        </Viewbox>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="ArrowBox" Property="Opacity" Value="0.5" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Arrow" Property="Fill" Value="{DynamicResource GrayBrush1}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="Arrow" Property="Fill" Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Width" Value="{DynamicResource HorizontalScrollBarRepeatButtonWidth}" />
    </Style>

    <Style x:Key="MetroScrollBarRepeatButtonLargeStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Interval" Value="50" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Rectangle
                        Width="{TemplateBinding Width}"
                        Height="{TemplateBinding Height}"
                        Fill="{TemplateBinding Background}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="MetroScrollBarThumbStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Background" Value="{DynamicResource ThumbBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Grid x:Name="ThumbVisual">
                        <Rectangle
                            x:Name="Background"
                            Fill="{TemplateBinding Background}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            StrokeThickness="{TemplateBinding BorderThickness}" />
                        <Rectangle
                            x:Name="MouseOverRectangle"
                            Fill="{DynamicResource BlackBrush}"
                            Opacity="0"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            StrokeThickness="{TemplateBinding BorderThickness}" />
                        <Rectangle
                            x:Name="PressedRectangle"
                            Fill="{DynamicResource BlackBrush}"
                            Opacity="0"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            StrokeThickness="{TemplateBinding BorderThickness}" />
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver" Storyboard="{StaticResource MetroScrollBarThumbMouseOverStoryboard}" />
                                <VisualState x:Name="Pressed" Storyboard="{StaticResource MetroScrollBarThumbPressedStoryboard}" />
                                <VisualState x:Name="Disabled" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="ThumbVisual" Property="Opacity" Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  fugging Scrollbars  -->
    <ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid x:Name="HorizontalRoot" Height="{TemplateBinding Height}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="0.00001*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <RepeatButton
                x:Name="HorizontalSmallDecrease"
                Grid.Column="0"
                Command="ScrollBar.LineLeftCommand"
                Content="M54,14.9765625L54,74.9765625 24,44.9765625 54,14.9765625z"
                Style="{DynamicResource MetroScrollBarRepeatButtonSmallStyle}" />
            <Track
                x:Name="PART_Track"
                Grid.Column="1"
                IsDirectionReversed="False">
                <Track.DecreaseRepeatButton>
                    <RepeatButton
                        x:Name="HorizontalLargeDecrease"
                        Command="ScrollBar.PageLeftCommand"
                        Style="{DynamicResource MetroScrollBarRepeatButtonLargeStyle}" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Controls:MetroThumb Margin="0,1,0,1" Style="{DynamicResource MetroScrollBarThumbStyle}" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton
                        x:Name="HorizontalLargeIncrease"
                        Command="ScrollBar.PageRightCommand"
                        Style="{DynamicResource MetroScrollBarRepeatButtonLargeStyle}" />
                </Track.IncreaseRepeatButton>
            </Track>
            <RepeatButton
                x:Name="HorizontalSmallIncrease"
                Grid.Column="2"
                Command="ScrollBar.LineRightCommand"
                Content="M192,79.875L352,239.875 192,399.875 192,79.875z"
                Style="{DynamicResource MetroScrollBarRepeatButtonSmallStyle}" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="HorizontalRoot" Property="Opacity" Value="0.5" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid x:Name="VerticalRoot" Width="{TemplateBinding Width}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="0.00001*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <RepeatButton
                x:Name="VerticalSmallDecrease"
                Grid.Row="0"
                Command="ScrollBar.LineUpCommand"
                Content="M240.125,160L400.125,320 80.125,320 240.125,160z"
                Style="{DynamicResource MetroScrollBarRepeatButtonSmallStyle}" />
            <Track
                x:Name="PART_Track"
                Grid.Row="1"
                IsDirectionReversed="True">
                <Track.Resources>
                    <System:Double x:Key="{x:Static SystemParameters.VerticalScrollBarButtonHeightKey}">50</System:Double>
                </Track.Resources>
                <Track.DecreaseRepeatButton>
                    <RepeatButton
                        x:Name="VerticalLargeDecrease"
                        Command="ScrollBar.PageUpCommand"
                        Style="{DynamicResource MetroScrollBarRepeatButtonLargeStyle}" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Controls:MetroThumb Margin="1,0,1,0" Style="{DynamicResource MetroScrollBarThumbStyle}" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton
                        x:Name="VerticalLargeIncrease"
                        Command="ScrollBar.PageDownCommand"
                        Style="{DynamicResource MetroScrollBarRepeatButtonLargeStyle}" />
                </Track.IncreaseRepeatButton>
            </Track>
            <RepeatButton
                x:Name="VerticalSmallIncrease"
                Grid.Row="2"
                Command="ScrollBar.LineDownCommand"
                Content="M80.125,192L400.125,192 240.125,352 80.125,192z"
                Style="{DynamicResource MetroScrollBarRepeatButtonSmallStyle}" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter TargetName="VerticalRoot" Property="Opacity" Value="0.5" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--  Style for overall  ScrollBar  -->
    <Style x:Key="MetroScrollBar" TargetType="{x:Type ScrollBar}">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="Height" Value="{DynamicResource MetroScrollBarHeight}" />
                <Setter Property="Template" Value="{DynamicResource HorizontalScrollBar}" />
                <Setter Property="Width" Value="Auto" />
            </Trigger>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Height" Value="Auto" />
                <Setter Property="Template" Value="{DynamicResource VerticalScrollBar}" />
                <Setter Property="Width" Value="{DynamicResource MetroScrollBarWidth}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="MetroScrollViewer" TargetType="{x:Type ScrollViewer}">
        <Setter Property="Controls:ScrollViewerHelper.VerticalScrollBarOnLeftSide" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid x:Name="Grid" Background="{TemplateBinding Background}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="leftColumn" Width="*" />
                            <ColumnDefinition x:Name="rightColumn" Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ScrollContentPresenter
                            x:Name="PART_ScrollContentPresenter"
                            Grid.Row="0"
                            Grid.Column="0"
                            Margin="{TemplateBinding Padding}"
                            CanContentScroll="{TemplateBinding CanContentScroll}"
                            CanHorizontallyScroll="False"
                            CanVerticallyScroll="False"
                            Content="{TemplateBinding Content}"
                            ContentTemplate="{TemplateBinding ContentTemplate}" />
                        <ScrollBar
                            x:Name="PART_VerticalScrollBar"
                            Grid.Row="0"
                            Grid.Column="1"
                            AutomationProperties.AutomationId="VerticalScrollBar"
                            Cursor="Arrow"
                            Maximum="{TemplateBinding ScrollableHeight}"
                            Minimum="0"
                            ViewportSize="{TemplateBinding ViewportHeight}"
                            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                            Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
                        <ScrollBar
                            x:Name="PART_HorizontalScrollBar"
                            Grid.Row="1"
                            Grid.Column="0"
                            AutomationProperties.AutomationId="HorizontalScrollBar"
                            Cursor="Arrow"
                            Maximum="{TemplateBinding ScrollableWidth}"
                            Minimum="0"
                            Orientation="Horizontal"
                            ViewportSize="{TemplateBinding ViewportWidth}"
                            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                            Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Controls:ScrollViewerHelper.VerticalScrollBarOnLeftSide" Value="True">
                            <Setter TargetName="PART_HorizontalScrollBar" Property="Grid.Column" Value="1" />
                            <Setter TargetName="PART_ScrollContentPresenter" Property="Grid.Column" Value="1" />
                            <Setter TargetName="PART_VerticalScrollBar" Property="Grid.Column" Value="0" />
                            <Setter TargetName="leftColumn" Property="Width" Value="Auto" />
                            <Setter TargetName="rightColumn" Property="Width" Value="*" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
