<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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:converters="clr-namespace:Fluent.Converters">
    <Style x:Key="ToolbarDropDownButtonStyle"
           TargetType="{x:Type Fluent:DropDownButton}">
        <Setter Property="Template"
                Value="{DynamicResource ToolbarDropDownButtonControlTemplate}" />
        <Setter Property="Height"
                Value="22" />
        <Setter Property="Width"
                Value="14" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
    </Style>

    <ControlTemplate x:Key="ToolbarDropDownButtonControlTemplate"
                     TargetType="{x:Type Fluent:DropDownButton}">
        <Grid>
            <Border x:Name="PART_ButtonBorder"
                    BorderThickness="1"
                    Background="Transparent"
                    BorderBrush="Transparent"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch">
                <ContentPresenter x:Name="iconImage"
                                  Width="8"
                                  Height="8"
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '8,8', {Binding RelativeSource={RelativeSource TemplatedParent}}}" />
            </Border>
            <Popup x:Name="PART_Popup"
                   Placement="Bottom"
                   IsOpen="{TemplateBinding IsDropDownOpen}"
                   AllowsTransparency="True"
                   Focusable="False"
                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
                   Margin="0,0,-4,0"
                   VerticalAlignment="Top"
                   Grid.ColumnSpan="2">
                <Grid Name="DropDown"
                      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 HorizontalAlignment="Stretch"
                                  VerticalAlignment="Top">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <ScrollViewer Margin="1"
                                              MaxHeight="{TemplateBinding MaxDropDownHeight}"
                                              SnapsToDevicePixels="True"
                                              ScrollViewer.VerticalScrollBarVisibility="Auto"
                                              ScrollViewer.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="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.25" />
            </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" />
                    <Condition Property="IsDropDownOpen"
                               Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="Background"
                        TargetName="PART_ButtonBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="PART_ButtonBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.BorderBrush}" />
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="QuickAccessToolbarStyle"
           TargetType="{x:Type Fluent:QuickAccessToolBar}">
        <Setter Property="Background"
                Value="{Binding Background, RelativeSource={RelativeSource AncestorType=Window}}" />
        <Setter Property="Template"
                Value="{DynamicResource QuickAccessToolbarControlTemplate}" />
    </Style>

    <ControlTemplate x:Key="QuickAccessToolbarControlTemplate"
                     TargetType="{x:Type Fluent:QuickAccessToolBar}">
        <DockPanel x:Name="PART_RootPanel"
                   KeyboardNavigation.TabNavigation="Local">
            <ContentControl x:Name="menuContentControl"
                            DockPanel.Dock="Right"
                            HorizontalAlignment="Right"
                            Focusable="False">
                <Fluent:DropDownButton CanAddToQuickAccessToolBar="False"
                                       x:Name="PART_MenuDownButton"
                                       HorizontalAlignment="Right"
                                       VerticalAlignment="Stretch"
                                       Style="{DynamicResource ToolbarDropDownButtonStyle}"
                                       DockPanel.Dock="Right"
                                       IsEnabled="{TemplateBinding IsEnabled}"
                                       Visibility="{Binding IsMenuDropDownVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}"
                                       Icon="{DynamicResource Fluent.Ribbon.Images.QuickAccessToolbarDropDown}"
                                       Size="Small"
                                       ToolTip="{Binding Source={x:Static Fluent:RibbonLocalization.Current}, Path=Localization.QuickAccessToolBarDropDownButtonTooltip, Mode=OneWay}"
                                       KeyboardNavigation.TabIndex="3">
                    <Fluent:GroupSeparatorMenuItem Style="{DynamicResource MenuGroupSeparatorStyle}"
                                                   Header="{Binding Source={x:Static Fluent:RibbonLocalization.Current}, Path=Localization.QuickAccessToolBarMenuHeader, Mode=OneWay}" />
                    <StackPanel x:Name="PART_MenuPanel" />
                    <Separator x:Name="menuSeparator"
                               Style="{DynamicResource MenuSeparatorStyle}" />
                    <Fluent:MenuItem x:Name="PART_ShowBelow"
                                     CanAddToQuickAccessToolBar="False"
                                     Header="{Binding Source={x:Static Fluent:RibbonLocalization.Current}, Path=Localization.QuickAccessToolBarMenuShowBelow, Mode=OneWay}" />
                    <Fluent:MenuItem x:Name="PART_ShowAbove"
                                     CanAddToQuickAccessToolBar="False"
                                     Header="{Binding Source={x:Static Fluent:RibbonLocalization.Current}, Path=Localization.QuickAccessToolBarMenuShowAbove, Mode=OneWay}"
                                     Visibility="Collapsed" />
                </Fluent:DropDownButton>
            </ContentControl>

            <Fluent:DropDownButton x:Name="PART_ToolbarDownButton"
                                   HorizontalAlignment="Right"
                                   Visibility="Collapsed"
                                   VerticalAlignment="Stretch"
                                   Style="{DynamicResource ToolbarDropDownButtonStyle}"
                                   DockPanel.Dock="Right"
                                   Fluent:KeyTip.Keys="00"
                                   Size="Small"
                                   IsEnabled="{TemplateBinding IsEnabled}"
                                   Icon="{DynamicResource Fluent.Ribbon.Images.QuickAccessToolbarExtender}"
                                   ToolTip="{Binding Source={x:Static Fluent:RibbonLocalization.Current}, Path=Localization.QuickAccessToolBarMoreControlsButtonTooltip, Mode=OneWay}"
                                   KeyboardNavigation.TabIndex="2"
                                   KeyboardNavigation.TabNavigation="Local">
                <Fluent:DropDownButton.ContextMenu>
                    <ContextMenu />
                </Fluent:DropDownButton.ContextMenu>

                <StackPanel Orientation="Horizontal"
                            Background="{TemplateBinding Background}"
                            Width="Auto"
                            Height="26"
                            Margin="-1">
                    <StackPanel Orientation="Horizontal"
                                x:Name="PART_ToolBarOverflowPanel"
                                HorizontalAlignment="Left"
                                Width="Auto"
                                Height="Auto"
                                VerticalAlignment="Center"
                                Margin="1,0,0,0" />
                    <ContentControl x:Name="popupContentControl"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Left"
                                    Background="{x:Null}"
                                    Focusable="False"
                                    Padding="0"
                                    Margin="1,0" />
                </StackPanel>
            </Fluent:DropDownButton>

            <StackPanel Orientation="Horizontal"
                        x:Name="PART_ToolBarPanel"
                        Width="Auto"
                        Height="Auto"
                        VerticalAlignment="Stretch"
                        KeyboardNavigation.TabNavigation="Local"
                        KeyboardNavigation.TabIndex="1" />
        </DockPanel>
        <ControlTemplate.Triggers>
            <Trigger Property="CanQuickAccessLocationChanging"
                     Value="False">
                <Setter Property="Visibility"
                        TargetName="PART_ShowBelow"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_ShowAbove"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="menuSeparator"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="ShowAboveRibbon"
                     Value="False">
                <Setter Property="Visibility"
                        TargetName="PART_ShowBelow"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_ShowAbove"
                        Value="Visible" />
                <Setter Property="Icon"
                        TargetName="PART_MenuDownButton"
                        Value="{DynamicResource Fluent.Ribbon.Images.QuickAccessToolbarDropDown.BelowRibbon}" />
                <Setter Property="Icon"
                        TargetName="PART_ToolbarDownButton"
                        Value="{DynamicResource Fluent.Ribbon.Images.QuickAccessToolbarExtender.BelowRibbon}" />
            </Trigger>
            <Trigger Property="HasOverflowItems"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="PART_ToolbarDownButton"
                        Value="Visible" />
                <Setter Property="Content"
                        TargetName="popupContentControl"
                        Value="{Binding ElementName=PART_MenuDownButton, Mode=OneWay}" />
                <Setter Property="Content"
                        TargetName="menuContentControl"
                        Value="{x:Null}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</ResourceDictionary>