<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:r="clr-namespace:ScreenToGif.Controls.Ribbon"
                    xmlns:c="clr-namespace:ScreenToGif.Controls"
                    xmlns:v="clr-namespace:ScreenToGif.Util.Converters">

    <v:ColorToAlpha x:Key="ColorToAlphaConverter"/>
    <v:InvertedBool x:Key="InvertedBool"/>

    <!--RibbonItem-->
    <Style TargetType="{x:Type r:RibbonItem}">
        <Setter Property="Background" Value="Transparent"/>

        <!--Button-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type r:RibbonItem}">
                    <c:ExtendedButton x:Name="RootButton" Text="{TemplateBinding Text}" Icon="{TemplateBinding Icon}" Command="{TemplateBinding Command}" CommandParameter="{TemplateBinding CommandParameter}"
                                      ContentHeight="28" ContentWidth="28" Style="{DynamicResource Style.Button.Vertical}"/>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IconSize" Value="Small">
                            <Setter TargetName="RootButton" Property="ContentHeight" Value="18"/>
                            <Setter TargetName="RootButton" Property="ContentWidth" Value="18"/>
                            <Setter TargetName="RootButton" Property="Style" Value="{DynamicResource Style.Button.Horizontal}"/>
                        </Trigger>
                        
                        <Trigger Property="IsTextVisible" Value="False">
                            <Setter TargetName="RootButton" Property="Text" Value="{x:Null}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Style.Triggers>
            <!--Dropdown-->
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding Source={RelativeSource FindAncestor, AncestorType={x:Type r:RibbonPanel}}, Path=Mode}" Value="Ribbon"/>
                    <Condition Binding="{Binding Source={RelativeSource Self}, Path=Mode}" Value="DropDownButton"/>
                </MultiDataTrigger.Conditions>

                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type r:RibbonItem}">
                            <c:DropDownButton x:Name="RootDropDownButton" Text="{TemplateBinding Text}" Icon="{TemplateBinding Icon}" ItemsSource="{TemplateBinding Menu}" MaxSize="28"/>

                            <ControlTemplate.Triggers>
                                <Trigger Property="IconSize" Value="Small">
                                    <Setter TargetName="RootDropDownButton" Property="MaxSize" Value="18"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </MultiDataTrigger>

            <!--Other-->
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding Source={RelativeSource FindAncestor, AncestorType={x:Type r:RibbonPanel}}, Path=Mode}" Value="Ribbon"/>
                    <Condition Binding="{Binding Source={RelativeSource Self}, Path=Mode}" Value="Other"/>
                </MultiDataTrigger.Conditions>

                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type r:RibbonItem}">
                            <ContentControl Content="{TemplateBinding Content}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </MultiDataTrigger>

            <!--Menu -> Other-->
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding Source={RelativeSource FindAncestor, AncestorType={x:Type r:RibbonPanel}}, Path=Mode}" Value="Menu"/>
                    <Condition Binding="{Binding Source={RelativeSource Self}, Path=Mode}" Value="Other"/>
                </MultiDataTrigger.Conditions>

                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type r:RibbonItem}">
                            <c:ExtendedMenuItem Header="{TemplateBinding Text}" Icon="{TemplateBinding Icon}" ItemsSource="{TemplateBinding Menu}">
                                <ContentControl Content="{TemplateBinding Content}"/>
                            </c:ExtendedMenuItem>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </MultiDataTrigger>
            
            <!--Menu-->
            <DataTrigger Binding="{Binding Source={RelativeSource FindAncestor, AncestorType={x:Type r:RibbonPanel}}, Path=Mode}" Value="Menu">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type r:RibbonItem}">
                            <c:ExtendedMenuItem Header="{TemplateBinding Text}" Icon="{TemplateBinding Icon}" ItemsSource="{TemplateBinding Menu}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <!--Ribbon Group-->
    <Style TargetType="{x:Type r:RibbonGroup}">
        <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
        <Setter Property="KeyboardNavigation.ControlTabNavigation" Value="Continue"/>
        <Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Continue"/>
        <Setter Property="KeyboardNavigation.TabNavigation" Value="Continue"/>

        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <r:RibbonGroupPanel/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type r:RibbonGroup}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="16"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <ItemsPresenter Grid.Row="0" Grid.Column="0"/>
                        <ContentPresenter Grid.Row="1" Grid.Column="0" ContentSource="Header" HorizontalAlignment="Center"/>

                        <Separator Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Margin="1,3" Width="1" BorderBrush="{DynamicResource Element.Border.Light}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Style.Triggers>
            <!--<Trigger Property="cr:RibbonBarPanel.GroupSizeIndex" Value="0"/>-->

            <Trigger Property="IsCollapsed" Value="True">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="r:RibbonGroup">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>

                                <r:RibbonItem Text="{TemplateBinding Header}" Icon="{Binding LargeIcon, RelativeSource={RelativeSource TemplatedParent}}">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="16"/>
                                        </Grid.RowDefinitions>

                                        <ItemsPresenter MaxHeight="74" />
                                        <ContentPresenter Grid.Row="1" ContentSource="Header" HorizontalAlignment="Center" />
                                    </Grid>
                                </r:RibbonItem>

                                <Separator Grid.Row="0" Grid.Column="1" Margin="1,3" Width="1" BorderBrush="{DynamicResource Element.Border.Light}"/>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

    <ControlTemplate x:Key="Template.Ribbon.Menu" TargetType="{x:Type r:Ribbon}">
        <Menu x:Name="MainMenu" ItemsSource="{TemplateBinding ItemsSource}"/>

        <!--<ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{DynamicResource Element.Background.Hover}"/>
                <Setter Property="BorderBrush" Value="{DynamicResource Element.Border.Hover}"/>
            </Trigger>
        </ControlTemplate.Triggers>-->
    </ControlTemplate>

    <ControlTemplate x:Key="Template.Ribbon.TabItem.Menu" TargetType="{x:Type r:RibbonTab}">

    </ControlTemplate>
</ResourceDictionary>