<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"
                    mc:Ignorable="d">
    <ControlTemplate x:Key="RibbonControlTemplate"
                     TargetType="{x:Type Fluent:Ribbon}">
        <ControlTemplate.Resources>
            <Style BasedOn="{StaticResource MenuSeparatorStyle}"
                   TargetType="{x:Type Separator}" />
        </ControlTemplate.Resources>
        
        <Border Background="{TemplateBinding Background}"
                BorderThickness="{TemplateBinding BorderThickness}"
                BorderBrush="{TemplateBinding BorderBrush}">
            <Grid x:Name="PART_LayoutRoot" 
                  Width="Auto"
                  Height="Auto">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                
                <Fluent:RibbonTabControl x:Name="PART_RibbonTabControl"
                                         Menu="{TemplateBinding Menu}"
                                         ContentHeight="{TemplateBinding ContentHeight}"
                                         ContextMenu="{Binding ContextMenu, ElementName=PART_LayoutRoot}"
                                         AreTabHeadersVisible="{TemplateBinding AreTabHeadersVisible}"
                                         IsToolBarVisible="{TemplateBinding IsToolBarVisible}"
                                         IsMouseWheelScrollingEnabled="{TemplateBinding IsMouseWheelScrollingEnabled}" />
                
                <ContentControl x:Name="quickAccessToolBarHolder"
                            Grid.Row="1"
                            Height="{TemplateBinding QuickAccessToolBarHeight}"
                            HorizontalAlignment="Left">
                    <Fluent:QuickAccessToolBar x:Name="PART_QuickAccessToolBar"
                                            ShowAboveRibbon="{Binding ShowQuickAccessToolBarAboveRibbon, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                            IsMenuDropDownVisible="{TemplateBinding IsQuickAccessToolBarMenuDropDownVisible}"
                                            HorizontalAlignment="Left"
                                            Focusable="False" />
                </ContentControl>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsQuickAccessToolBarVisible"
                     Value="False">
                <Setter Property="Visibility"
                        TargetName="quickAccessToolBarHolder"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="PART_QuickAccessToolBar"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsCollapsed"
                     Value="True">
                <Setter Property="Visibility"
                        TargetName="PART_RibbonTabControl"
                        Value="Collapsed" />
                <Setter Property="Visibility"
                        TargetName="quickAccessToolBarHolder"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="QuickAccessToolBar"
                     Value="{x:Null}">
                <Setter Property="Content"
                        TargetName="quickAccessToolBarHolder"
                        Value="{x:Null}" />
                <Setter Property="Visibility"
                        TargetName="quickAccessToolBarHolder"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="ShowQuickAccessToolBarAboveRibbon"
                     Value="True">
                <Setter Property="Content"
                        TargetName="quickAccessToolBarHolder"
                        Value="{x:Null}" />
                <Setter Property="Visibility"
                        TargetName="quickAccessToolBarHolder"
                        Value="Collapsed" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="RibbonStyle"
           TargetType="{x:Type Fluent:Ribbon}">
        <Setter Property="Background"
                Value="{DynamicResource Fluent.Ribbon.Brushes.Ribbon.Background}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="Template"
                Value="{DynamicResource RibbonControlTemplate}" />
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="VerticalAlignment"
                Value="Top" />
        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="Fluent:FrameworkHelper.UseLayoutRounding"
                Value="True" />
        <Setter Property="TitleBar"
                Value="{Binding TitleBar, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Fluent:IRibbonWindow}}, FallbackValue={x:Null}}" />
        <Setter Property="QuickAccessToolBarHeight"
                Value="{Binding TitleBar.ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:IRibbonWindow}}, FallbackValue=23}" />
    </Style>
</ResourceDictionary>
