<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Fluent="clr-namespace:Fluent">
    <!--Button in Scroll Control Style-->
    <ControlTemplate x:Key="ScrollButtonControlTemplate"
                     TargetType="{x:Type RepeatButton}">
        <Border Background="{DynamicResource Fluent.Ribbon.Brushes.ScrollViewer.Button.Background}">
            <Border x:Name="OuterBorder"
                    BorderThickness="1"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.ScrollViewer.Button.BorderBrush}"
                    Height="Auto"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.ScrollViewer.Button.Background}">
                <ContentPresenter HorizontalAlignment="Center"
                                    VerticalAlignment="Center" />
            </Border>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver"
                     Value="True">
                <Setter Property="Background"
                        TargetName="OuterBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="OuterBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}" />
            </Trigger>
            <Trigger Property="IsKeyboardFocusWithin"
                     Value="True">
                <Setter Property="Background"
                        TargetName="OuterBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="OuterBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="ScrollButtonStyle"
           TargetType="{x:Type RepeatButton}">
        <Setter Property="Template"
                Value="{DynamicResource ScrollButtonControlTemplate}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
    </Style>

    <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />

    <Style x:Key="RibbonScrollViewer"
           TargetType="{x:Type ScrollViewer}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid x:Name="Grid"
                          Background="{TemplateBinding Background}"
                          IsHitTestVisible="True">
                        <ScrollContentPresenter  Margin="{TemplateBinding Padding}"
                                                 x:Name="PART_ScrollContentPresenter"
                                                 Content="{TemplateBinding Content}"
                                                 ContentTemplate="{TemplateBinding ContentTemplate}"
                                                 CanContentScroll="{TemplateBinding CanContentScroll}"
                                                 IsHitTestVisible="True" />
                        <RepeatButton Command="{x:Static ScrollBar.LineLeftCommand}"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Focusable="false"
                                      HorizontalAlignment="Left"
                                      Width="13"
                                      Height="Auto"
                                      VerticalAlignment="Stretch"
                                      Style="{DynamicResource ScrollButtonStyle}">
                            <RepeatButton.Visibility>
                                <MultiBinding FallbackValue="Visibility.Collapsed"
                                              Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              ConverterParameter="0">
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ComputedHorizontalScrollBarVisibility" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="HorizontalOffset" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ExtentWidth" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ViewportWidth" />
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path Fill="{DynamicResource BlackBrush}"
                                  Stretch="Fill"
                                  Stroke="{x:Null}"
                                  StrokeThickness="0"
                                  HorizontalAlignment="Center"
                                  Margin="0"
                                  VerticalAlignment="Center"
                                  Width="3"
                                  Height="5"
                                  Data="M0,0L1,1 1,-1z" />
                        </RepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.LineRightCommand}"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Focusable="false"
                                      HorizontalAlignment="Right"
                                      Width="13"
                                      Height="Auto"
                                      VerticalAlignment="Stretch"
                                      Style="{DynamicResource ScrollButtonStyle}">
                            <RepeatButton.Visibility>
                                <MultiBinding FallbackValue="Visibility.Collapsed"
                                              Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              ConverterParameter="100">
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ComputedHorizontalScrollBarVisibility" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="HorizontalOffset" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ExtentWidth" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ViewportWidth" />
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path Fill="{DynamicResource BlackBrush}"
                                  Stretch="Fill"
                                  Stroke="{x:Null}"
                                  StrokeThickness="0"
                                  HorizontalAlignment="Center"
                                  Margin="0"
                                  VerticalAlignment="Center"
                                  Width="3"
                                  Height="5"
                                  Data="M1,0L0,1 0,-1z" />
                        </RepeatButton>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="CanContentScroll"
                Value="True" />
        <Setter Property="HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="VerticalScrollBarVisibility"
                Value="Disabled" />
        <Setter Property="Focusable"
                Value="False" />
    </Style>

    <Style x:Key="RibbonTabScrollViewer"
           TargetType="{x:Type ScrollViewer}">
        <Setter Property="OverridesDefaultStyle"
                Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid x:Name="Grid"
                          Background="{TemplateBinding Background}"
                          IsHitTestVisible="True">
                        <ScrollContentPresenter  Margin="{TemplateBinding Padding}"
                                                 x:Name="PART_ScrollContentPresenter"
                                                 Content="{TemplateBinding Content}"
                                                 ContentTemplate="{TemplateBinding ContentTemplate}"
                                                 CanContentScroll="{TemplateBinding CanContentScroll}"
                                                 IsHitTestVisible="True" />
                        <RepeatButton Command="{x:Static ScrollBar.LineLeftCommand}"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Focusable="false"
                                      HorizontalAlignment="Left"
                                      Width="13"
                                      Height="Auto"
                                      VerticalAlignment="Stretch"
                                      Style="{DynamicResource ScrollButtonStyle}"
                                      Margin="0">
                            <RepeatButton.Visibility>
                                <MultiBinding FallbackValue="Visibility.Collapsed"
                                              Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              ConverterParameter="0">
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ComputedHorizontalScrollBarVisibility" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="HorizontalOffset" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ExtentWidth" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ViewportWidth" />
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path Fill="{DynamicResource BlackBrush}"
                                  Stretch="Fill"
                                  Stroke="{x:Null}"
                                  StrokeThickness="0"
                                  HorizontalAlignment="Center"
                                  Margin="0"
                                  VerticalAlignment="Center"
                                  Width="3"
                                  Height="5"
                                  Data="M0,0L1,1 1,-1z" />
                        </RepeatButton>
                        <RepeatButton Command="{x:Static ScrollBar.LineRightCommand}"
                                      CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                      Focusable="false"
                                      HorizontalAlignment="Right"
                                      Width="13"
                                      Height="Auto"
                                      VerticalAlignment="Stretch"
                                      Style="{DynamicResource ScrollButtonStyle}"
                                      Margin="0">
                            <RepeatButton.Visibility>
                                <MultiBinding FallbackValue="Visibility.Collapsed"
                                              Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                              ConverterParameter="100">
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ComputedHorizontalScrollBarVisibility" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="HorizontalOffset" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ExtentWidth" />
                                    <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                             Path="ViewportWidth" />
                                </MultiBinding>
                            </RepeatButton.Visibility>
                            <Path Fill="{DynamicResource BlackBrush}"
                                  Stretch="Fill"
                                  Stroke="{x:Null}"
                                  StrokeThickness="0"
                                  HorizontalAlignment="Center"
                                  Margin="0"
                                  VerticalAlignment="Center"
                                  Width="3"
                                  Height="5"
                                  Data="M1,0L0,1 0,-1z" />
                        </RepeatButton>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="CanContentScroll"
                Value="True" />
        <Setter Property="HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="VerticalScrollBarVisibility"
                Value="Disabled" />
        <Setter Property="Focusable"
                Value="False" />

    </Style>

    <Style x:Key="MenuScrollViewer"
           TargetType="{x:Type ScrollViewer}">
        <Setter Property="OverridesDefaultStyle"
                Value="True" />
        <Setter Property="Template"
                Value="{StaticResource MenuScrollViewerControlTemplate}" />
        <Setter Property="CanContentScroll"
                Value="False" />
        <Setter Property="HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="VerticalScrollBarVisibility"
                Value="Disabled" />
        <Setter Property="Focusable"
                Value="False" />
    </Style>

    <ControlTemplate TargetType="{x:Type ScrollViewer}"
                     x:Key="MenuScrollViewerControlTemplate">
        <Grid x:Name="Grid"
              Background="{TemplateBinding Background}"
              IsHitTestVisible="True">
            <ScrollContentPresenter  Margin="{TemplateBinding Padding}"
                                     x:Name="PART_ScrollContentPresenter"
                                     Content="{TemplateBinding Content}"
                                     ContentTemplate="{TemplateBinding ContentTemplate}"
                                     CanContentScroll="{TemplateBinding CanContentScroll}"
                                     IsHitTestVisible="True" />
            <RepeatButton ClickMode="Hover"
                          Command="{x:Static ScrollBar.LineUpCommand}"
                          CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                          Focusable="false"
                          HorizontalAlignment="Stretch"
                          Width="Auto"
                          Height="12"
                          VerticalAlignment="Top"
                          Style="{DynamicResource ScrollButtonStyle}">
                <RepeatButton.Visibility>
                    <MultiBinding FallbackValue="Visibility.Collapsed"
                                  Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                  ConverterParameter="0">
                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                 Path="ComputedVerticalScrollBarVisibility" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                 Path="VerticalOffset" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                 Path="ExtentHeight" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                 Path="ViewportHeight" />
                    </MultiBinding>
                </RepeatButton.Visibility>
                <Path Stretch="Fill"
                      Stroke="{x:Null}"
                      StrokeThickness="0"
                      HorizontalAlignment="Center"
                      Margin="0"
                      VerticalAlignment="Center"
                      Width="5"
                      Height="3"
                      Data="M0,0L1,-1 2,0z"
                      Fill="{DynamicResource BlackBrush}" />

            </RepeatButton>
            <RepeatButton ClickMode="Hover"
                          Command="{x:Static ScrollBar.LineDownCommand}"
                          CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                          Focusable="false"
                          HorizontalAlignment="Stretch"
                          Width="Auto"
                          Height="12"
                          VerticalAlignment="Bottom"
                          Style="{DynamicResource ScrollButtonStyle}">
                <RepeatButton.Visibility>
                    <MultiBinding FallbackValue="Visibility.Collapsed"
                                  Converter="{StaticResource MenuScrollingVisibilityConverter}"
                                  ConverterParameter="100">
                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                 Path="ComputedVerticalScrollBarVisibility" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                 Path="VerticalOffset" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                 Path="ExtentHeight" />
                        <Binding RelativeSource="{RelativeSource TemplatedParent}"
                                 Path="ViewportHeight" />
                    </MultiBinding>
                </RepeatButton.Visibility>
                <Path Stretch="Fill"
                      Stroke="{x:Null}"
                      StrokeThickness="0"
                      HorizontalAlignment="Center"
                      Margin="0"
                      VerticalAlignment="Center"
                      Width="5"
                      Height="3"
                      Data="M0,0L1,1 2,0z"
                      Fill="{DynamicResource BlackBrush}" />
            </RepeatButton>
        </Grid>
    </ControlTemplate>

    <Style x:Key="ScrollViewerStyle"
           TargetType="{x:Type ScrollViewer}">
        <Style.Resources>
            <Style x:Key="{x:Type ScrollBar}"
                   TargetType="{x:Type ScrollBar}"
                   BasedOn="{StaticResource ScrollBarWhite}" />
        </Style.Resources>

        <Setter Property="Template"
                Value="{DynamicResource ScrollViewerControlTemplate}" />

        <Style.Triggers>
            <Trigger Property="IsEnabled"
                     Value="false">
                <Setter Property="Foreground"
                        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="Fluent.Ribbon.Styles.RibbonGroupsContainerScrollViewer"
           TargetType="{x:Type Fluent:RibbonGroupsContainerScrollViewer}"
           BasedOn="{StaticResource RibbonScrollViewer}">
    </Style>

    <ControlTemplate x:Key="ScrollViewerControlTemplate"
                     TargetType="{x:Type ScrollViewer}">
        <Border BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}">
            <Grid x:Name="Grid"
                  Background="{TemplateBinding Background}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Rectangle x:Name="Corner"
                           Grid.Column="1"
                           Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
                           Grid.Row="1" />
                <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                        CanContentScroll="{TemplateBinding CanContentScroll}"
                                        CanHorizontallyScroll="False"
                                        CanVerticallyScroll="False"
                                        ContentTemplate="{TemplateBinding ContentTemplate}"
                                        Content="{TemplateBinding Content}"
                                        Grid.Column="0"
                                        Margin="{TemplateBinding Padding}"
                                        Grid.Row="0" />
                <ScrollBar x:Name="PART_VerticalScrollBar"
                           AutomationProperties.AutomationId="VerticalScrollBar"
                           Cursor="Arrow"
                           Grid.Column="1"
                           Maximum="{TemplateBinding ScrollableHeight}"
                           Minimum="0"
                           Grid.Row="0"
                           Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                           Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                           ViewportSize="{TemplateBinding ViewportHeight}" />
                <ScrollBar x:Name="PART_HorizontalScrollBar"
                           AutomationProperties.AutomationId="HorizontalScrollBar"
                           Cursor="Arrow"
                           Grid.Column="0"
                           Maximum="{TemplateBinding ScrollableWidth}"
                           Minimum="0"
                           Orientation="Horizontal"
                           Grid.Row="1"
                           Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                           Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                           ViewportSize="{TemplateBinding ViewportWidth}" />
            </Grid>
        </Border>
    </ControlTemplate>
</ResourceDictionary>