<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:Fluent="clr-namespace:Fluent"
                    xmlns:converters="clr-namespace:Fluent.Converters"
                    mc:Ignorable="d">

    <!--Button in Spinner Control Style-->
    <ControlTemplate x:Key="SpinnerButtonControlTemplate"
                     TargetType="{x:Type RepeatButton}">
        <Border x:Name="border"
                BorderThickness="1"
                Background="Transparent"
                BorderBrush="Transparent"
                Height="Auto"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch">
            <ContentPresenter x:Name="contentPresenter"
                              HorizontalAlignment="Center"
                              VerticalAlignment="Center" />
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver"
                     Value="False" />
            <Trigger Property="IsPressed"
                     Value="True">
                <Setter Property="BorderBrush"
                        TargetName="border"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Pressed.BorderBrush}" />
                <Setter Property="Background"
                        TargetName="border"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Pressed.Background}" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="contentPresenter"
                        Value="0.5" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver"
                               Value="True" />
                    <Condition Property="IsPressed"
                               Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="Background"
                        TargetName="border"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="border"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}" />
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

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

    <!--Spinner Style-->
    <ControlTemplate TargetType="{x:Type Fluent:Spinner}"
                     x:Key="Fluent.Ribbon.ControlTemplates.Spinner">
        <Grid Width="Auto"
              Height="22"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal"
                        Grid.ColumnSpan="1"
                        x:Name="headerAndIconPanel"
                        HorizontalAlignment="Left"
                        Margin="0,0,4,0">
                <ContentPresenter x:Name="iconImage"
                                  Width="16"
                                  Height="16"
                                  VerticalAlignment="Center"
                                  Margin="4,0,0,0"
                                  Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}" />

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="{Binding Path=(Fluent:RibbonGroupBoxWrapPanel.SharedSizeGroupName), RelativeSource={RelativeSource TemplatedParent}}" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{TemplateBinding Header}"
                               TextWrapping="Wrap"
                               VerticalAlignment="Center"
                               Margin="5,0,0,0"
                               x:Name="headerTextBlock" />
                </Grid>
            </StackPanel>

            <Border x:Name="PART_ContentBorder"
                    Height="22"
                    BorderThickness="1"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.TextBox.BorderBrush}"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Background}"
                    Grid.ColumnSpan="1"
                    Grid.Column="1"
                    Width="{TemplateBinding InputWidth}"
                    HorizontalAlignment="Right">
                <Grid Grid.ColumnSpan="1"
                        Grid.Column="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="17" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <TextBox x:Name="PART_TextBox"
                             Style="{x:Null}"
                             BorderThickness="0"
                             Grid.RowSpan="2"
                             Grid.Column="0"
                             Background="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Background}"
                             Foreground="{TemplateBinding Foreground}"
                             CaretBrush="{DynamicResource Fluent.Ribbon.Brushes.TextBox.CaretBrush}"
                             SelectionBrush="{DynamicResource Fluent.Ribbon.Brushes.TextBox.SelectionBrush}"
                             Padding="2,0,2,0"
                             Margin="0"
                             VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />

                    <Path Visibility="Collapsed"
                            HorizontalAlignment="Left"
                            Margin="0,-1,0,-1"
                            x:Name="path"
                            Width="1"
                            Fill="{DynamicResource BlackBrush}"
                            Stretch="Fill"
                            Stroke="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.BorderBrush}"
                            StrokeThickness="1"
                            Grid.Column="1"
                            Grid.RowSpan="2"
                            Data="M0,0L0,1" />

                    <Path HorizontalAlignment="Left"
                            Margin="0,0,-1,0"
                            Width="Auto"
                            Fill="{DynamicResource BlackBrush}"
                            Stretch="Fill"
                            Stroke="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.BorderBrush}"
                            StrokeThickness="1"
                            Data="M0,0L1,0"
                            Visibility="Collapsed"
                            x:Name="path1"
                            VerticalAlignment="Bottom"
                            Height="1"
                            Grid.Column="1"
                            Grid.RowSpan="1" />

                    <RepeatButton x:Name="PART_ButtonUp"
                                    Grid.Column="1"
                                    Grid.Row="0"
                                    Style="{DynamicResource SpinnerButtonStyle}"
                                    RenderTransformOrigin="0,0.5"
                                    HorizontalAlignment="Stretch">
                        <Path Width="5"
                                Height="3"
                                Fill="{DynamicResource BlackBrush}"
                                Stretch="Fill"
                                Stroke="{DynamicResource BlackBrush}"
                                Data="M0,0L1,-1 2,0"
                                HorizontalAlignment="Center"
                                StrokeThickness="0"
                                VerticalAlignment="Center"
                                Margin="1,2,0,1"
                                RenderOptions.EdgeMode="Aliased" />
                    </RepeatButton>
                    <RepeatButton x:Name="PART_ButtonDown"
                                    Grid.Column="1"
                                    Grid.Row="1"
                                    Style="{DynamicResource SpinnerButtonStyle}">
                        <Path Width="5"
                                Height="3"
                                Fill="{DynamicResource BlackBrush}"
                                Stretch="Fill"
                                Stroke="{DynamicResource BlackBrush}"
                                Data="M0,0L1,1 2,0"
                                StrokeThickness="0"
                                HorizontalAlignment="Center"
                                Margin="1,-1,0,0"
                                VerticalAlignment="Center"
                                RenderOptions.EdgeMode="Aliased" />
                    </RepeatButton>
                </Grid>
            </Border>
        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="Icon"
                        Value="{x:Null}">
                <Setter Property="Visibility"
                        TargetName="iconImage"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="InputWidth"
                        Value="NaN">
                <Setter Property="HorizontalAlignment"
                        TargetName="PART_ContentBorder"
                        Value="Stretch" />
            </Trigger>
            <Trigger Property="IsEnabled"
                        Value="False">
                <Setter Property="IsEnabled"
                        TargetName="PART_TextBox"
                        Value="False" />
                <Setter Property="Background"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Disabled.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Disabled.BorderBrush}" />
                <Setter Property="Background"
                        TargetName="PART_TextBox"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Disabled.Background}" />
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="headerTextBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Size"
                        Value="Middle">
                <Setter Property="Visibility"
                        TargetName="headerTextBlock"
                        Value="Collapsed" />
                <Setter Property="HorizontalAlignment"
                        TargetName="PART_ContentBorder"
                        Value="Stretch" />
            </Trigger>
            <Trigger Property="Size"
                        Value="Small">
                <Setter Property="Visibility"
                        TargetName="headerAndIconPanel"
                        Value="Collapsed" />
                <Setter Property="HorizontalAlignment"
                        TargetName="PART_ContentBorder"
                        Value="Stretch" />
            </Trigger>
            <Trigger Property="IsMouseOver"
                        Value="True">
                <Setter Property="Visibility"
                        TargetName="path"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="path1"
                        Value="Visible" />
                <Setter Property="BorderBrush"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.BorderBrush}" />
                <Setter Property="Background"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.Background}" />
                <Setter Property="Background"
                        TargetName="PART_TextBox"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.Background}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="SpinnerStyle"
           TargetType="{x:Type Fluent:Spinner}">
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="Focusable"
                Value="False" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="Template"
                Value="{DynamicResource Fluent.Ribbon.ControlTemplates.Spinner}" />
    </Style>
</ResourceDictionary>