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

    <ControlTemplate x:Key="Fluent.Ribbon.Templates.WindowCommands.CaptionButton"
                     TargetType="{x:Type Button}">
        <Grid Background="{TemplateBinding Background}">
            <ContentPresenter x:Name="contentPresenter"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              Margin="{TemplateBinding Padding}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                              RecognizesAccessKey="True" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver"
                     Value="True">
                <Setter TargetName="contentPresenter"
                        Property="Opacity"
                        Value="1" />
            </Trigger>
            <Trigger Property="IsMouseOver"
                     Value="False">
                <Setter TargetName="contentPresenter"
                        Property="Opacity"
                        Value="0.75" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Foreground"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.WhiteBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="Fluent.Ribbon.Styles.WindowCommands.CaptionButton"
           TargetType="{x:Type Button}">
        <Setter Property="Background"
                Value="{DynamicResource Fluent.Ribbon.Brushes.WindowCommands.CaptionButton.Background}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.WindowCommands.CaptionButton.Foreground}" />
        <Setter Property="VerticalAlignment"
                Value="Stretch" />
        <Setter Property="HorizontalContentAlignment"
                Value="Center" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="Padding"
                Value="1" />
        <Setter Property="Width"
                Value="46" />
        <Setter Property="Template"
                Value="{DynamicResource Fluent.Ribbon.Templates.WindowCommands.CaptionButton}" />
        <Style.Triggers>
            <Trigger Property="IsMouseOver"
                     Value="True">
                <Setter Property="Background"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.WindowCommands.CaptionButton.MouseOver.Background}" />
            </Trigger>
            <Trigger Property="IsPressed"
                     Value="True">
                <Setter Property="Background"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.WindowCommands.CaptionButton.Pressed.Background}" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <ControlTemplate x:Key="RibbonButtonControlTemplate"
                     TargetType="{x:Type Fluent:Button}">
        <Border x:Name="border"
                BorderThickness="{TemplateBinding BorderThickness}"
                Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                VerticalAlignment="{TemplateBinding VerticalAlignment}"
                Height="Auto">
            <StackPanel x:Name="stackPanel"
                        Width="Auto"
                        Margin="{TemplateBinding Padding}"
                        Orientation="Vertical">
                <ContentPresenter x:Name="iconImage"
                                  HorizontalAlignment="Center"
                                  Height="32"
                                  VerticalAlignment="Center"
                                  Content="{converters:ObjectToImageConverter {Binding LargeIcon, RelativeSource={RelativeSource TemplatedParent}}, '32,32', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                                  Width="32"
                                  Margin="0 2 0 0"
                                  SnapsToDevicePixels="True" />
                <Fluent:TwoLineLabel x:Name="controlLabel"
                                     Text="{TemplateBinding Header}"
                                     HorizontalAlignment="Stretch"
                                     VerticalAlignment="Center"
                                     Margin="2 0 2 0" />
            </StackPanel>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Size"
                     Value="Small">
                <Setter Property="Orientation"
                        TargetName="stackPanel"
                        Value="Horizontal" />
                <Setter Property="Visibility"
                        TargetName="controlLabel"
                        Value="Collapsed" />
                <Setter Property="HasTwoLines"
                        TargetName="controlLabel"
                        Value="False" />
                <Setter Property="Width"
                        TargetName="iconImage"
                        Value="16" />
                <Setter Property="Height"
                        TargetName="iconImage"
                        Value="16" />
                <Setter Property="Margin"
                        TargetName="iconImage"
                        Value="2,0,2,0" />
                <Setter Property="Content"
                        TargetName="iconImage"
                        Value="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}" />
                <Setter Property="Margin"
                        TargetName="controlLabel"
                        Value="2,0,2,0" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Middle">
                <Setter Property="Orientation"
                        TargetName="stackPanel"
                        Value="Horizontal" />
                <Setter Property="Width"
                        TargetName="stackPanel"
                        Value="Auto" />
                <Setter Property="VerticalAlignment"
                        TargetName="iconImage"
                        Value="Center" />
                <Setter Property="HasTwoLines"
                        TargetName="controlLabel"
                        Value="False" />
                <Setter Property="Margin"
                        TargetName="controlLabel"
                        Value="2,0,2,0" />
                <Setter Property="VerticalAlignment"
                        TargetName="border"
                        Value="Stretch" />
                <Setter Property="Width"
                        TargetName="iconImage"
                        Value="16" />
                <Setter Property="Height"
                        TargetName="iconImage"
                        Value="16" />
                <Setter Property="Margin"
                        TargetName="iconImage"
                        Value="2,0,2,0" />
                <Setter Property="Content"
                        TargetName="iconImage"
                        Value="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}" />
                <Setter Property="VerticalAlignment"
                        TargetName="controlLabel"
                        Value="Center" />
            </Trigger>
            <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="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="controlLabel"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver"
                               Value="True" />
                    <Condition Property="IsPressed"
                               Value="False" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </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="RibbonButtonStyle"
           TargetType="{x:Type Fluent:Button}">
        <Setter Property="Template"
                Value="{DynamicResource RibbonButtonControlTemplate}" />
        <Setter Property="Height"
                Value="68" />
        <Setter Property="Width"
                Value="Auto" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="Background"
                Value="Transparent" />
        <Setter Property="BorderBrush"
                Value="Transparent" />
        <Setter Property="SnapsToDevicePixels"
                Value="False" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Style.Triggers>
            <Trigger Property="Size"
                     Value="Large">
                <Setter Property="Height"
                        Value="68" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Middle">
                <Setter Property="Height"
                        Value="22" />
                <Setter Property="HorizontalAlignment"
                        Value="Left" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Small">
                <Setter Property="Height"
                        Value="22" />
                <Setter Property="Width"
                        Value="22" />
                <Setter Property="HorizontalAlignment"
                        Value="Left" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>