<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">
    <Style x:Key="RibbonSplitButtonStyle"
           TargetType="{x:Type Fluent:SplitButton}">
        <Setter Property="Template"
                Value="{DynamicResource RibbonSplitButtonControlTemplate}" />
        <Setter Property="Height"
                Value="68" />
        <Setter Property="Width"
                Value="Auto" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="SnapsToDevicePixels"
                Value="False" />
        <Setter Property="HorizontalAlignment"
                Value="Left" />
        <Setter Property="Fluent:KeyTip.AutoPlacement"
                Value="False" />
        <Style.Triggers>
            <Trigger Property="Size"
                     Value="Large">
                <Setter Property="Height"
                        Value="68" />
                <Setter Property="Fluent:KeyTip.HorizontalAlignment"
                        Value="Center" />
                <Setter Property="Fluent:KeyTip.VerticalAlignment"
                        Value="Bottom" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Middle">
                <Setter Property="Height"
                        Value="22" />
                <Setter Property="Fluent:KeyTip.HorizontalAlignment"
                        Value="Right" />
                <Setter Property="Fluent:KeyTip.VerticalAlignment"
                        Value="Center" />
                <Setter Property="Fluent:KeyTip.Margin"
                        Value="0,0,-5,0" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Small">
                <Setter Property="Height"
                        Value="22" />
                <Setter Property="Width"
                        Value="32" />
                <Setter Property="Fluent:KeyTip.HorizontalAlignment"
                        Value="Right" />
                <Setter Property="Fluent:KeyTip.VerticalAlignment"
                        Value="Center" />
                <Setter Property="Fluent:KeyTip.Margin"
                        Value="0,0,-5,0" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <ControlTemplate x:Key="RibbonSplitButtonControlTemplate"
                     TargetType="{x:Type Fluent:SplitButton}">
        <ControlTemplate.Resources>
            <Style BasedOn="{StaticResource MenuSeparatorStyle}"
                   TargetType="{x:Type Separator}" />
        </ControlTemplate.Resources>
        <Grid>
            <Border BorderThickness="1"
                    Name="PART_ButtonBorder"
                    BorderBrush="Transparent"
                    Background="Transparent"
                    VerticalAlignment="Stretch">
                <StackPanel Orientation="Vertical"
                            Name="stackPanel"
                            KeyboardNavigation.TabNavigation="Local">
                    <Fluent:ToggleButton x:Name="PART_Button"
                                         Command="{TemplateBinding Command}"
                                         CommandParameter="{TemplateBinding CommandParameter}"
                                         CommandTarget="{TemplateBinding CommandTarget}"
                                         Margin="0,0,0,0"
                                         Height="Auto"
                                         Width="Auto"
                                         Style="{DynamicResource InnerButtonStyle}"
                                         LargeIcon="{Binding LargeIcon, RelativeSource={RelativeSource TemplatedParent}}"
                                         Icon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}"
                                         IsEnabled="{Binding IsButtonEnabled, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                         Header="{TemplateBinding Header}"
                                         ToolTip="{TemplateBinding ToolTip}"
                                         GroupName="{Binding GroupName, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                         IsChecked="{Binding IsChecked, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                         IsDefinitive="{TemplateBinding IsDefinitive}"
                                         CanAddToQuickAccessToolBar="{TemplateBinding CanAddButtonToQuickAccessToolBar}" />
                    <Border BorderThickness="0,0,0,0"
                            Name="downBorder"
                            BorderBrush="Transparent"
                            Background="Transparent"
                            Margin="0,0,0,0">
                        <Grid>
                            <Fluent:TwoLineLabel x:Name="controlLabel"
                                                 Text="{TemplateBinding Header}"
                                                 HorizontalAlignment="Center"
                                                 VerticalAlignment="Center"
                                                 Margin="2,1,2,2"
                                                 HasGlyph="{TemplateBinding HasTriangle}" />
                        </Grid>
                    </Border>
                </StackPanel>
            </Border>
            <Popup x:Name="PART_Popup"
                   Placement="Bottom"
                   IsOpen="{TemplateBinding IsDropDownOpen}"
                   AllowsTransparency="True"
                   Focusable="False"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
                   Margin="0,0,-4,0"
                   VerticalAlignment="Top"
                   Grid.ColumnSpan="2">
                <Grid Name="DropDown"
                      IsEnabled="{TemplateBinding IsEnabled}"
                      SnapsToDevicePixels="True"
                      Margin="0"
                      VerticalAlignment="Top">
                    <Border x:Name="PART_DropDownBorder"
                            MinWidth="{TemplateBinding ActualWidth}"
                            SnapsToDevicePixels="True"
                            Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                            BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BorderBrush}"
                            BorderThickness="1"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Top">
                        <Grid Width="Auto"
                              Height="Auto"
                              HorizontalAlignment="Stretch"
                              VerticalAlignment="Top">
                            <Border VerticalAlignment="Top"
                                    Width="Auto"
                                    Height="Auto"
                                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.BackgroundBrush}"
                                    BorderThickness="1" />
                            <Grid Margin="1"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Top">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <ScrollViewer x:Name="PART_ScrollViewer"
                                              Style="{DynamicResource MenuScrollViewer}"
                                              Margin="1"
                                              MaxHeight="{TemplateBinding MaxDropDownHeight}"
                                              SnapsToDevicePixels="True"
                                              VerticalScrollBarVisibility="Auto"
                                              HorizontalScrollBarVisibility="Hidden">
                                    <StackPanel x:Name="PART_MenuPanel"
                                                Orientation="Vertical"
                                                IsItemsHost="True"
                                                KeyboardNavigation.DirectionalNavigation="Cycle" />
                                </ScrollViewer>
                                <Border x:Name="resizeBorder"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Top"
                                        Height="11"
                                        BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.DropDown.Resize.BorderBrush}"
                                        BorderThickness="0,1,0,0"
                                        Grid.Row="1"
                                        Background="{DynamicResource Fluent.Ribbon.Brushes.DropDown.Resize.BackgroundBrush}">
                                    <Grid>
                                        <Thumb x:Name="PART_ResizeVerticalThumb"
                                               HorizontalAlignment="Stretch"
                                               Margin="0,0,0,-90"
                                               Width="Auto"
                                               Height="10"
                                               VerticalAlignment="Top"
                                               Cursor="SizeNS"
                                               Template="{DynamicResource ResizeVerticalThumbControlTemplate}" />
                                        <Thumb x:Name="PART_ResizeBothThumb"
                                               HorizontalAlignment="Right"
                                               Margin="0,0,0,-90"
                                               Width="10"
                                               Height="10"
                                               VerticalAlignment="Top"
                                               Cursor="SizeNWSE"
                                               Template="{DynamicResource ResizeBothThumbControlTemplate}" />
                                    </Grid>
                                </Border>
                            </Grid>
                        </Grid>
                    </Border>
                </Grid>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="ResizeMode"
                     Value="None">
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="ResizeMode"
                     Value="Both">
                <Setter Property="Visibility"
                        TargetName="PART_ResizeVerticalThumb"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_ResizeBothThumb"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Visible" />
            </Trigger>
            <Trigger Property="ResizeMode"
                     Value="Vertical">
                <Setter Property="Visibility"
                        TargetName="PART_ResizeBothThumb"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_ResizeVerticalThumb"
                        Value="Visible" />
                <Setter Property="Visibility"
                        TargetName="resizeBorder"
                        Value="Visible" />
            </Trigger>
            <Trigger Property="IsChecked"
                     Value="True">
                <Setter Property="BorderBrush"
                        TargetName="PART_ButtonBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Pressed.BorderBrush}" />
                <Setter Property="Background"
                        TargetName="PART_ButtonBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Pressed.Background}" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Small">
                <Setter Property="Size"
                        TargetName="PART_Button"
                        Value="Small" />
                <Setter Property="Orientation"
                        TargetName="stackPanel"
                        Value="Horizontal" />
                <Setter Property="Width"
                        TargetName="controlLabel"
                        Value="10" />
                <Setter Property="Margin"
                        TargetName="controlLabel"
                        Value="0,-19,0,0" />
                <Setter Property="Text"
                        TargetName="controlLabel"
                        Value="" />
                <Setter Property="Padding"
                        TargetName="downBorder"
                        Value="1,0,0,0" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Middle">
                <Setter Property="Size"
                        TargetName="PART_Button"
                        Value="Middle" />
                <Setter Property="Orientation"
                        TargetName="stackPanel"
                        Value="Horizontal" />
                <Setter Property="Width"
                        TargetName="controlLabel"
                        Value="10" />
                <Setter Property="Margin"
                        TargetName="controlLabel"
                        Value="0,-19,0,0" />
                <Setter Property="Text"
                        TargetName="controlLabel"
                        Value="" />
            </Trigger>

            <Trigger Property="IsButtonEnabled"
                     Value="False">
                <Setter Property="IsEnabled"
                        TargetName="PART_Button"
                        Value="False" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="IsEnabled"
                        TargetName="PART_Button"
                        Value="False" />
                <Setter Property="Opacity"
                        TargetName="controlLabel"
                        Value="0.5" />
            </Trigger>
            <Trigger Property="IsDropDownOpen"
                     Value="True">
                <Setter Property="BorderBrush"
                        TargetName="PART_ButtonBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Pressed.BorderBrush}" />
                <Setter Property="Background"
                        TargetName="PART_ButtonBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.Pressed.Background}" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver"
                               Value="True"
                               SourceName="PART_Button" />
                    <Condition Property="IsDropDownOpen"
                               Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="BorderBrush"
                        TargetName="PART_ButtonBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver"
                               Value="True"
                               SourceName="downBorder" />
                    <Condition Property="IsDropDownOpen"
                               Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="BorderBrush"
                        TargetName="PART_ButtonBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}" />
                <Setter Property="Background"
                        TargetName="downBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}" />
                <Setter Property="BorderBrush"
                        TargetName="downBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}" />
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!--Inner Button Style (Button in SplitButton)-->
    <Style x:Key="InnerButtonStyle"
           TargetType="{x:Type Fluent:ToggleButton}">
        <Setter Property="Template"
                Value="{DynamicResource InnerButtonControlTemplate}" />
        <Setter Property="VerticalAlignment"
                Value="Stretch" />
        <Setter Property="HorizontalAlignment"
                Value="Stretch" />
        <Setter Property="Fluent:KeyTip.AutoPlacement"
                Value="{Binding Path=(Fluent:KeyTip.AutoPlacement), RelativeSource={RelativeSource AncestorType={x:Type Fluent:SplitButton}}}" />
        <Style.Triggers>
            <Trigger Property="Size"
                     Value="Large">
                <Setter Property="Fluent:KeyTip.HorizontalAlignment"
                        Value="Center" />
                <Setter Property="Fluent:KeyTip.VerticalAlignment"
                        Value="Top" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Middle">
                <Setter Property="Fluent:KeyTip.HorizontalAlignment"
                        Value="Left" />
                <Setter Property="Fluent:KeyTip.VerticalAlignment"
                        Value="Center" />
                <Setter Property="Fluent:KeyTip.Margin"
                        Value="-5,0,0,0" />
            </Trigger>
            <Trigger Property="Size"
                     Value="Small">
                <Setter Property="Fluent:KeyTip.HorizontalAlignment"
                        Value="Left" />
                <Setter Property="Fluent:KeyTip.VerticalAlignment"
                        Value="Center" />
                <Setter Property="Fluent:KeyTip.Margin"
                        Value="-5,0,0,0" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <ControlTemplate x:Key="InnerButtonControlTemplate"
                     TargetType="{x:Type Fluent:ToggleButton}">
        <Border x:Name="border"
                BorderThickness="0"
                Background="Transparent"
                BorderBrush="Transparent"
                Height="Auto"
                HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                VerticalAlignment="{TemplateBinding VerticalAlignment}"
                SnapsToDevicePixels="False">
            <Grid Height="Auto">
                <Rectangle x:Name="rectangle"
                           StrokeThickness="0"
                           Visibility="Collapsed">
                </Rectangle>
                <StackPanel x:Name="stackPanel"
                            Width="Auto"
                            Orientation="Vertical"
                            HorizontalAlignment="Stretch"
                            SnapsToDevicePixels="True">
                    <ContentPresenter x:Name="iconImage"
                                      Margin="0,1,0,0"
                                      HorizontalAlignment="Center"
                                      Height="32"
                                      VerticalAlignment="Center"
                                      Content="{converters:ObjectToImageConverter {Binding LargeIcon, RelativeSource={RelativeSource TemplatedParent}}, '32,32', {Binding RelativeSource={RelativeSource TemplatedParent}}}"
                                      Width="32"
                                      SnapsToDevicePixels="True" />
                    <Fluent:TwoLineLabel x:Name="controlLabel"
                                         Text="{TemplateBinding Header}"
                                         HorizontalAlignment="Stretch"
                                         VerticalAlignment="Center"
                                         Margin="2,0,2,2"
                                         Visibility="Collapsed" />
                </StackPanel>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <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>
            <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>
            <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>
            <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="1,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,1" />
            </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,-1,1" />
                <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="1,0,2,0" />
                <Setter Property="Content"
                        TargetName="iconImage"
                        Value="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}" />
                <Setter Property="Visibility"
                        TargetName="controlLabel"
                        Value="Visible" />
                <Setter Property="VerticalAlignment"
                        TargetName="controlLabel"
                        Value="Center" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</ResourceDictionary>