<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:converters="clr-namespace:Fluent.Converters"
                    xmlns:styleSelectors="clr-namespace:Fluent.StyleSelectors">
    <ControlTemplate x:Key="Fluent.Ribbon.Templates.BackstageTabControl.Button"
                     TargetType="{x:Type Fluent:Button}">
        <Grid Background="Transparent">
            <Border x:Name="border"
                    Visibility="Collapsed"
                    Background="{TemplateBinding Fluent:RibbonProperties.MouseOverBackground}" />
            <StackPanel Orientation="Horizontal"
                        Margin="25,0,15,0"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center">
                <ContentPresenter x:Name="iconImage"
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  Width="16"
                                  Height="16"
                                  Margin="0 0 8 0"
                                  Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}"                              
                                  SnapsToDevicePixels="True" />

                <ContentControl x:Name="controlLabel"
                                Focusable="False"
                                Content="{TemplateBinding Header}">
                    <ContentControl.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextWrapping"
                                    Value="NoWrap" />
                            <Setter Property="TextTrimming"
                                    Value="CharacterEllipsis" />
                        </Style>
                    </ContentControl.Resources>
                </ContentControl>
            </StackPanel>
        </Grid>
        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Visible" />
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsKeyboardFocused"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="controlLabel"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="Fluent.Ribbon.Styles.BackstageTabControl.Button"
           TargetType="{x:Type Fluent:Button}">
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="Height"
                Value="38" />
        <Setter Property="Margin"
                Value="0" />
        <Setter Property="Template"
                Value="{DynamicResource Fluent.Ribbon.Templates.BackstageTabControl.Button}" />
        <Setter Property="Fluent:RibbonProperties.MouseOverBackground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.BackstageTabItem.MouseOver.Background}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.IdealForegroundColorBrush}" />
    </Style>

    <ControlTemplate x:Key="BackstageBackButtonTemplate"
                     TargetType="Button">
        <Grid x:Name="ContentGrid"
              Background="Transparent"
              Fluent:FrameworkHelper.UseLayoutRounding="False">
            <ContentControl Margin="{TemplateBinding Padding}"
                            HorizontalAlignment="Left"
                            Focusable="False">
                <Grid>
                    <Path x:Name="arrowpath"
                          Width="16"
                          Height="12"
                          Stretch="Uniform"
                          Fill="{TemplateBinding Foreground}"
                          Data="F1 M 36,22L 36,26L 19.75,26L 27,33L 20.5,33L 11,24L 20.5,15L 27,15L 19.75,22L 36,22 Z " />

                    <Ellipse x:Name="backellipse"
                             Stroke="{TemplateBinding Foreground}"
                             Height="34"
                             Width="34"
                             StrokeThickness="2" />

                    <Path Data="M0,0 C0,35 0,35 0,35 C0,35 35,35 35,35 L35,0 z"
                          Fill="Transparent"
                          HorizontalAlignment="Stretch"
                          Margin="0"
                          Stretch="None"
                          Width="Auto" />
                </Grid>
            </ContentControl>
        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="IsKeyboardFocused"
                     Value="True">
                <Setter Property="Background"
                        TargetName="ContentGrid"
                        Value="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" />
                <Setter Property="Opacity"
                        TargetName="arrowpath"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="backellipse"
                        Value="0.5" />
            </Trigger>
            <Trigger Property="IsMouseOver"
                     Value="True">
                <Setter Property="Background"
                        TargetName="ContentGrid"
                        Value="{Binding Background, RelativeSource={RelativeSource TemplatedParent}}" />
                <Setter Property="Opacity"
                        TargetName="arrowpath"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="backellipse"
                        Value="0.5" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="BackstageBackButtonStyle"
           TargetType="{x:Type Button}">
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="Height"
                Value="48" />
        <Setter Property="HorizontalAlignment"
                Value="Stretch" />
        <Setter Property="Template"
                Value="{DynamicResource BackstageBackButtonTemplate}" />
        <Setter Property="Background"
                Value="{DynamicResource Fluent.Ribbon.Brushes.Backstage.BackButton.Background}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.Backstage.BackButton.Foreground}" />
    </Style>

    <Style TargetType="{x:Type Fluent:SeparatorTabItem}"
           x:Key="Fluent.Ribbon.Styles.BackstageTabControl.SeparatorTabItem">
        <Setter Property="Margin"
                Value="25,10,20,10" />
        <Setter Property="Focusable"
                Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Fluent:SeparatorTabItem}">
                    <StackPanel>
                        <TextBlock x:Name="header"
                                   Margin="10,5"
                                   TextWrapping="Wrap"
                                   Text="{TemplateBinding Header}"
                                   VerticalAlignment="Center"
                                   FontSize="14"
                                   FontWeight="SemiBold"
                                   Foreground="{DynamicResource Fluent.Ribbon.Brushes.IdealForegroundColorBrush}"
                                   Visibility="Visible" />
                        <Line MinWidth="75"
                              Height="1"
                              X2="1"
                              Stroke="{DynamicResource HighTransparentWhiteBrush}"
                              Stretch="Uniform" />
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasHeader"
                                 Value="False">
                            <Setter TargetName="header"
                                    Property="Visibility"
                                    Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="BackstageControlTemplate"
                     TargetType="{x:Type Fluent:BackstageTabControl}">
        <ControlTemplate.Resources>
            <ResourceDictionary>
                <Style x:Key="{x:Type ScrollBar}"
                       TargetType="{x:Type ScrollBar}"
                       BasedOn="{StaticResource ScrollBarWhite}" />
                
                <Style x:Key="{x:Type Fluent:Button}"
                       TargetType="{x:Type Fluent:Button}"
                       BasedOn="{StaticResource Fluent.Ribbon.Styles.Backstage.Button}" />
                <Style x:Key="{x:Type Fluent:ToggleButton}"
                       TargetType="{x:Type Fluent:ToggleButton}"
                       BasedOn="{StaticResource Fluent.Ribbon.Styles.Backstage.ToggleButton}" />
                <Style x:Key="{x:Type Fluent:DropDownButton}"
                       TargetType="{x:Type Fluent:DropDownButton}"
                       BasedOn="{StaticResource Fluent.Ribbon.Styles.Backstage.DropDownButton}" />
                <Style x:Key="{x:Type Fluent:ComboBox}"
                       TargetType="{x:Type Fluent:ComboBox}"
                       BasedOn="{StaticResource Fluent.Ribbon.Styles.Backstage.ComboBox}" />
            </ResourceDictionary>
        </ControlTemplate.Resources>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="{TemplateBinding ItemsPanelMinWidth}"
                                  Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Grid x:Name="PART_ItemsPanelGrid"
                  VerticalAlignment="Stretch"
                  Background="{DynamicResource WhiteBrush}">
                <Grid Background="{TemplateBinding ItemsPanelBackground}">
                    <Fluent:WindowSteeringHelperControl Height="{Binding SelectedContentMargin.Top, RelativeSource={RelativeSource TemplatedParent}}"
                                                        VerticalAlignment="Top"
                                                        IsEnabled="{TemplateBinding IsWindowSteeringHelperEnabled}" />

                    <Button x:Name="backbutton"
                            Style="{DynamicResource BackstageBackButtonStyle}"
                            Command="{x:Static Fluent:RibbonCommands.OpenBackstage}"
                            Visibility="{Binding Path=IsBackButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource boolToVisibilityConverter}}"
                            Margin="0,16,0,0"
                            Padding="22,7,0,7"
                            VerticalAlignment="Top">
                    </Button>

                    <ItemsPresenter Margin="0,77,0,0"
                                    Height="Auto" />
                </Grid>
            </Grid>

            <Grid x:Name="PART_SelectedContentGrid"
                  Height="Auto"
                  Grid.Column="1"
                  Margin="{TemplateBinding SelectedContentMargin}"
                  Background="{DynamicResource WhiteBrush}">
                <Border Background="{TemplateBinding Background}">
                    <ContentPresenter x:Name="PART_SelectedContentHost"
                                      HorizontalAlignment="Stretch"
                                      VerticalAlignment="Stretch"
                                      Height="Auto"
                                      ContentSource="SelectedContent" />
                </Border>
            </Grid>
        </Grid>
    </ControlTemplate>

    <Style x:Key="BackstageStyle"
           TargetType="{x:Type Fluent:BackstageTabControl}">
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="Template"
                Value="{DynamicResource BackstageControlTemplate}" />
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="Background"
                Value="{DynamicResource WhiteBrush}" />
        <Setter Property="ItemsPanelBackground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.BackstageTabControl.ItemsPanelBackground}" />
        <Setter Property="ItemContainerStyleSelector"
                Value="{x:Static styleSelectors:BackstageTabControlItemContainerStyleSelector.Instance}" />
        <Setter Property="SelectedContentMargin">
            <Setter.Value>
                <MultiBinding Converter="{x:Static converters:StaticConverters.ThicknessConverter}">
                    <Binding Source="0" />
                    <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Fluent:IRibbonWindow}}"
                             Path="TitleBar.ActualHeight"
                             FallbackValue="0" />
                    <Binding Source="0" />
                    <Binding Source="0" />
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>