<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Behaviours="clr-namespace:MahApps.Metro.Behaviours"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TabControl.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="ScrollBarRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Foreground" Value="{DynamicResource GrayBrush3}" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Grid HorizontalAlignment="Center"
                          VerticalAlignment="Center"
                          Background="{TemplateBinding Background}">
                        <ContentControl x:Name="PART_Arrow"
                                        Width="12"
                                        Height="12"
                                        Content="{TemplateBinding Content}"
                                        Foreground="{TemplateBinding Foreground}"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                        Style="{DynamicResource PathIconContentControlStyle}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="PART_Arrow" Property="Opacity" Value="0.5" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="PART_Arrow" Property="Foreground" Value="{DynamicResource GrayBrush1}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="PART_Arrow" Property="Foreground" Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="HorizontalScrollBarTemplate" TargetType="{x:Type ScrollBar}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <RepeatButton Grid.Column="0"
                          Width="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"
                          Command="ScrollBar.PageLeftCommand"
                          Content="M6 2L0 8l6 6z"
                          Style="{DynamicResource ScrollBarRepeatButtonStyle}" />
            <RepeatButton Grid.Column="2"
                          Width="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"
                          Command="ScrollBar.PageRightCommand"
                          Content="M0 14l6-6-6-6z"
                          Style="{DynamicResource ScrollBarRepeatButtonStyle}" />
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalScrollBarTemplate" TargetType="{x:Type ScrollBar}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <RepeatButton Grid.Row="0"
                          Height="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"
                          Command="ScrollBar.PageUpCommand"
                          Content="M12 11L6 5l-6 6z"
                          Style="{DynamicResource ScrollBarRepeatButtonStyle}" />
            <RepeatButton Grid.Row="2"
                          Height="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"
                          Command="ScrollBar.PageDownCommand"
                          Content="M0 5l6 6 6-6z"
                          Style="{DynamicResource ScrollBarRepeatButtonStyle}" />
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="ScrollViewerTemplate" TargetType="{x:Type ScrollViewer}">
        <Grid>
            <ScrollBar x:Name="PART_HorizontalScrollBar"
                       Height="14"
                       AutomationProperties.AutomationId="HorizontalScrollBar"
                       Cursor="Arrow"
                       Maximum="{TemplateBinding ScrollableWidth}"
                       Minimum="0"
                       Orientation="Horizontal"
                       Template="{DynamicResource HorizontalScrollBarTemplate}"
                       ViewportSize="{TemplateBinding ViewportWidth}"
                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                       Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            <ScrollBar x:Name="PART_VerticalScrollBar"
                       Width="14"
                       AutomationProperties.AutomationId="VerticalScrollBar"
                       Cursor="Arrow"
                       Maximum="{TemplateBinding ScrollableHeight}"
                       Minimum="0"
                       Orientation="Vertical"
                       Template="{DynamicResource VerticalScrollBarTemplate}"
                       ViewportSize="{TemplateBinding ViewportHeight}"
                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                       Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            <Grid Margin="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid Grid.Row="0"
                      Grid.Column="1"
                      Height="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"
                      Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />
                <Grid Grid.Row="1"
                      Grid.Column="0"
                      Width="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"
                      Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" />
                <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                        Grid.Row="1"
                                        Grid.Column="1"
                                        CanContentScroll="{TemplateBinding CanContentScroll}"
                                        CanHorizontallyScroll="False"
                                        CanVerticallyScroll="False"
                                        Content="{TemplateBinding Content}"
                                        ContentTemplate="{TemplateBinding ContentTemplate}" />
                <Grid Grid.Row="1"
                      Grid.Column="2"
                      Width="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"
                      Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" />
                <Grid Grid.Row="2"
                      Grid.Column="1"
                      Height="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"
                      Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />
            </Grid>
        </Grid>
    </ControlTemplate>

    <!--  obsolete  -->
    <ControlTemplate x:Key="VerticalScrollViewerTemplate" TargetType="{x:Type ScrollViewer}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <ScrollBar x:Name="PART_VerticalScrollBar"
                       Grid.Row="0"
                       Grid.Column="0"
                       Width="14"
                       AutomationProperties.AutomationId="VerticalScrollBar"
                       Cursor="Arrow"
                       Maximum="{TemplateBinding ScrollableHeight}"
                       Minimum="0"
                       Orientation="Vertical"
                       Template="{DynamicResource VerticalScrollBarTemplate}"
                       ViewportSize="{TemplateBinding ViewportHeight}"
                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                       Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />
            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                    Grid.Row="0"
                                    Grid.Column="0"
                                    Margin="2 14 2 14"
                                    HorizontalAlignment="Center"
                                    CanContentScroll="{TemplateBinding CanContentScroll}"
                                    CanHorizontallyScroll="False"
                                    CanVerticallyScroll="False"
                                    Content="{TemplateBinding Content}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}" />
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="HorizontalAnimatedSingleRowTabControl" TargetType="{x:Type TabControl}">
        <Grid KeyboardNavigation.TabNavigation="Local">
            <Grid.RowDefinitions>
                <RowDefinition x:Name="RowDefinition0" Height="Auto" />
                <RowDefinition x:Name="RowDefinition1" Height="*" />
            </Grid.RowDefinitions>
            <ScrollViewer x:Name="HeaderPanelScroll"
                          Grid.Row="0"
                          Panel.ZIndex="1"
                          Controls:ScrollViewerHelper.IsHorizontalScrollWheelEnabled="{TemplateBinding Controls:ScrollViewerHelper.IsHorizontalScrollWheelEnabled}"
                          HorizontalScrollBarVisibility="Auto"
                          Template="{StaticResource ScrollViewerTemplate}"
                          VerticalScrollBarVisibility="Disabled">
                <Grid x:Name="HeaderPanelGrid">
                    <Controls:Underline x:Name="Underline"
                                        Background="Transparent"
                                        BorderBrush="{TemplateBinding Controls:TabControlHelper.UnderlineBrush}"
                                        LineThickness="1"
                                        Placement="Bottom"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                        Visibility="Collapsed" />
                    <TabPanel x:Name="HeaderPanel"
                              IsItemsHost="true"
                              KeyboardNavigation.TabIndex="1" />
                </Grid>
            </ScrollViewer>
            <Controls:TransitioningContentControl x:Name="ContentPanel"
                                                  Grid.Row="1"
                                                  Behaviours:ReloadBehavior.OnSelectedTabChanged="True"
                                                  RestartTransitionOnContentChange="True"
                                                  Transition="{TemplateBinding Controls:TabControlHelper.Transition}"
                                                  UseLayoutRounding="True">
                <ContentPresenter x:Name="PART_SelectedContentHost"
                                  Margin="{TemplateBinding Padding}"
                                  ContentSource="SelectedContent"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  UseLayoutRounding="False" />
            </Controls:TransitioningContentControl>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Controls:TabControlHelper.Underlined" Value="TabPanel">
                <Setter TargetName="Underline" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Top">
                <Setter TargetName="ContentPanel" Property="Grid.Row" Value="1" />
                <Setter TargetName="HeaderPanelScroll" Property="Grid.Row" Value="0" />
                <Setter TargetName="HeaderPanelScroll" Property="Margin" Value="2 2 2 0" />
                <Setter TargetName="RowDefinition0" Property="Height" Value="Auto" />
                <Setter TargetName="RowDefinition1" Property="Height" Value="*" />
                <Setter TargetName="Underline" Property="Placement" Value="Bottom" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Bottom">
                <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
                <Setter TargetName="HeaderPanelScroll" Property="Grid.Row" Value="1" />
                <Setter TargetName="HeaderPanelScroll" Property="Margin" Value="2 0 2 2" />
                <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
                <Setter TargetName="RowDefinition1" Property="Height" Value="Auto" />
                <Setter TargetName="Underline" Property="Placement" Value="Top" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="VerticalAnimatedSingleRowTabControl" TargetType="{x:Type TabControl}">
        <Grid KeyboardNavigation.TabNavigation="Local">
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Name="ColumnDefinition0" Width="*" />
                <ColumnDefinition x:Name="ColumnDefinition1" Width="Auto" />
            </Grid.ColumnDefinitions>
            <ScrollViewer x:Name="HeaderPanelScroll"
                          Grid.Column="1"
                          Panel.ZIndex="1"
                          HorizontalScrollBarVisibility="Disabled"
                          Template="{StaticResource ScrollViewerTemplate}"
                          VerticalScrollBarVisibility="Auto">
                <Grid x:Name="HeaderPanelGrid">
                    <Controls:Underline x:Name="Underline"
                                        Background="Transparent"
                                        BorderBrush="{TemplateBinding Controls:TabControlHelper.UnderlineBrush}"
                                        LineThickness="1"
                                        Placement="Bottom"
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                        Visibility="Collapsed" />
                    <TabPanel x:Name="HeaderPanel"
                              IsItemsHost="true"
                              KeyboardNavigation.TabIndex="1" />
                </Grid>
            </ScrollViewer>
            <Controls:TransitioningContentControl x:Name="ContentPanel"
                                                  Grid.Column="0"
                                                  Behaviours:ReloadBehavior.OnSelectedTabChanged="True"
                                                  RestartTransitionOnContentChange="True"
                                                  Transition="{TemplateBinding Controls:TabControlHelper.Transition}"
                                                  UseLayoutRounding="True">
                <ContentPresenter x:Name="PART_SelectedContentHost"
                                  Margin="{TemplateBinding Padding}"
                                  ContentSource="SelectedContent"
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                  UseLayoutRounding="False" />
            </Controls:TransitioningContentControl>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="Controls:TabControlHelper.Underlined" Value="TabPanel">
                <Setter TargetName="Underline" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Left">
                <Setter TargetName="ColumnDefinition0" Property="Width" Value="Auto" />
                <Setter TargetName="ColumnDefinition1" Property="Width" Value="*" />
                <Setter TargetName="ContentPanel" Property="Grid.Column" Value="1" />
                <Setter TargetName="HeaderPanelScroll" Property="Grid.Column" Value="0" />
                <Setter TargetName="HeaderPanelScroll" Property="Margin" Value="2 2 0 2" />
                <Setter TargetName="Underline" Property="Placement" Value="Right" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Right">
                <Setter TargetName="ColumnDefinition0" Property="Width" Value="*" />
                <Setter TargetName="ColumnDefinition1" Property="Width" Value="Auto" />
                <Setter TargetName="ContentPanel" Property="Grid.Column" Value="0" />
                <Setter TargetName="HeaderPanelScroll" Property="Grid.Column" Value="1" />
                <Setter TargetName="HeaderPanelScroll" Property="Margin" Value="0 2 2 2" />
                <Setter TargetName="Underline" Property="Placement" Value="Left" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style BasedOn="{StaticResource MetroTabControl}" TargetType="{x:Type TabControl}">
        <Setter Property="Controls:ScrollViewerHelper.IsHorizontalScrollWheelEnabled" Value="True" />
        <Setter Property="Controls:TabControlHelper.Transition" Value="Left" />
        <Setter Property="Template" Value="{StaticResource HorizontalAnimatedSingleRowTabControl}" />
        <Style.Triggers>
            <Trigger Property="TabStripPlacement" Value="Top">
                <Setter Property="Template" Value="{StaticResource HorizontalAnimatedSingleRowTabControl}" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Bottom">
                <Setter Property="Template" Value="{StaticResource HorizontalAnimatedSingleRowTabControl}" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Left">
                <Setter Property="Template" Value="{StaticResource VerticalAnimatedSingleRowTabControl}" />
            </Trigger>
            <Trigger Property="TabStripPlacement" Value="Right">
                <Setter Property="Template" Value="{StaticResource VerticalAnimatedSingleRowTabControl}" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>