<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">
    <Style x:Key="Fluent.Ribbon.ColorGallery.ListBox.ItemContainerStyle" TargetType="{x:Type ListBoxItem}">
        <Setter Property="Padding"
                Value="{Binding Padding, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, FallbackValue='2,0,2,0'}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                    <Grid Background="Transparent">
                        <ContentPresenter Margin="{TemplateBinding Padding}"
                                          Width="{Binding ChipWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:ColorGallery}}, FallbackValue=13}"
                                          Height="{Binding ChipHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:ColorGallery}}, FallbackValue=13}" />
                        <Border x:Name="outerBorder"
                                BorderThickness="1"
                                Margin="{TemplateBinding Padding}">
                            <Border x:Name="innerBorder"
                                    BorderThickness="1" />
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected"
                                 Value="True">
                            <Setter Property="BorderBrush"
                                    TargetName="outerBorder"
                                    Value="{DynamicResource Fluent.Ribbon.Brushes.DarkExtremeHighlightBrush}" />
                            <Setter Property="BorderBrush"
                                    TargetName="innerBorder"
                                    Value="{DynamicResource Fluent.Ribbon.Brushes.DarkExtremeHighlightBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter Property="BorderBrush"
                                    TargetName="outerBorder"
                                    Value="{DynamicResource Fluent.Ribbon.Brushes.DarkExtremeHighlightBrush}" />
                            <Setter Property="BorderBrush"
                                    TargetName="innerBorder"
                                    Value="{DynamicResource Fluent.Ribbon.Brushes.ExtremeHighlightBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Content">
                <Trigger.Value>
                    <Color />
                </Trigger.Value>
                <Setter Property="Opacity"
                        Value="0" />
                <Setter Property="IsHitTestVisible"
                        Value="False" />
            </Trigger>
        </Style.Triggers>
    </Style>
    
    <DataTemplate x:Key="Fluent.Ribbon.ColorGallery.ListBox.ItemTemplate">
        <Rectangle Stroke="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Item.BorderBrush}"
                   Fill="{Binding Converter={x:Static converters:StaticConverters.ColorToSolidColorBrushValueConverter}}" />
    </DataTemplate>
    
    <ControlTemplate x:Key="Fluent.Ribbon.ColorGallery.ListBox.Template.Row0" TargetType="{x:Type ListBox}">
        <Border Background="{TemplateBinding Background}"
                HorizontalAlignment="Stretch">
            <UniformGrid HorizontalAlignment="Left"
                         IsItemsHost="True"
                         Columns="{Binding Columns, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:ColorGallery}}}" />
        </Border>
    </ControlTemplate>
    
    <ControlTemplate x:Key="Fluent.Ribbon.ColorGallery.ListBox.Template.Row1" TargetType="{x:Type ListBox}">
        <Border Background="{TemplateBinding Background}"
                HorizontalAlignment="Stretch">
            <UniformGrid Rows="1"
                         HorizontalAlignment="Left"
                         IsItemsHost="True"
                         Columns="{Binding Columns, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:ColorGallery}}}" />
        </Border>
    </ControlTemplate>
    
    <Style x:Key="ColorGalleryListBox"
           TargetType="{x:Type ListBox}">
        <Setter Property="Background"
                Value="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Background}" />
        <Setter Property="ItemTemplate"
                Value="{DynamicResource Fluent.Ribbon.ColorGallery.ListBox.ItemTemplate}" />
        <Setter Property="Template"
                Value="{DynamicResource Fluent.Ribbon.ColorGallery.ListBox.Template.Row1}" />
        <Setter Property="ItemContainerStyle"
                Value="{DynamicResource Fluent.Ribbon.ColorGallery.ListBox.ItemContainerStyle}" />
    </Style>

    <Style x:Key="HightlightColorGalleryListBox"
           TargetType="{x:Type ListBox}">
        <Setter Property="Background"
                Value="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Background}" />
        <Setter Property="ItemTemplate"
                Value="{DynamicResource Fluent.Ribbon.ColorGallery.ListBox.ItemTemplate}" />
        <Setter Property="Template"
                Value="{DynamicResource Fluent.Ribbon.ColorGallery.ListBox.Template.Row0}" />
        <Setter Property="ItemContainerStyle"
                Value="{DynamicResource Fluent.Ribbon.ColorGallery.ListBox.ItemContainerStyle}" />
    </Style>

    <Fluent:ColorGradientItemTemplateSelector x:Key="ColorGradientItemTemplateSelect" />

    <DataTemplate x:Key="GradientColorCenterDataTemplate">
        <Border BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Item.BorderBrush}"
                BorderThickness="1,0,1,0"
                Background="{Binding Converter={x:Static converters:StaticConverters.ColorToSolidColorBrushValueConverter}}" />
    </DataTemplate>

    <DataTemplate x:Key="GradientColorTopDataTemplate">
        <Border BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Item.BorderBrush}"
                BorderThickness="1,1,1,0"
                Background="{Binding Converter={x:Static converters:StaticConverters.ColorToSolidColorBrushValueConverter}}" />
    </DataTemplate>

    <DataTemplate x:Key="GradientColorBottomDataTemplate">
        <Border BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Item.BorderBrush}"
                BorderThickness="1,0,1,1"
                Background="{Binding Converter={x:Static converters:StaticConverters.ColorToSolidColorBrushValueConverter}}" />
    </DataTemplate>

    <Style x:Key="ColorGalleryGradientListBox"
           TargetType="{x:Type ListBox}">
        <Setter Property="Background"
                Value="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Background}" />
        <Setter Property="ItemTemplateSelector"
                Value="{DynamicResource ColorGradientItemTemplateSelect}" />
        <Setter Property="Template"
                Value="{DynamicResource Fluent.Ribbon.ColorGallery.ListBox.Template.Row0}" />
        <Setter Property="ItemContainerStyle"
                Value="{DynamicResource Fluent.Ribbon.ColorGallery.ListBox.ItemContainerStyle}" />
    </Style>

    <Style TargetType="{x:Type Fluent:ColorGallery}">
        <Setter Property="ChipWidth"
                Value="13" />
        <Setter Property="ChipHeight"
                Value="13" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Fluent:ColorGallery}">
                    <StackPanel KeyboardNavigation.DirectionalNavigation="Contained">
                        <Fluent:MenuItem x:Name="PART_AutomaticColor"
                                         Header="{Binding Source={x:Static Fluent:RibbonLocalization.Current}, Path=Localization.Automatic, Mode=OneWay}">
                            <Fluent:MenuItem.Icon>
                                <Rectangle Width="16"
                                           Height="16"
                                           Stroke="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Item.BorderBrush}"
                                           Fill="{DynamicResource BlackBrush}"
                                           Margin="-2,0,0,0" />
                            </Fluent:MenuItem.Icon>
                        </Fluent:MenuItem>
                        <ScrollViewer HorizontalScrollBarVisibility="Disabled"
                                      VerticalScrollBarVisibility="Auto">
                            <StackPanel Background="{TemplateBinding Background}"
                                        ClipToBounds="True"
                                        Margin="0,1,0,1"
                                        KeyboardNavigation.DirectionalNavigation="Contained">
                                <Fluent:GroupSeparatorMenuItem Header="Theme Colors"
                                                               x:Name="themeColorsSeparator" />
                                <ListBox KeyboardNavigation.DirectionalNavigation="Contained"
                                         x:Name="PART_ThemeColorsListBox"
                                         ItemsSource="{Binding ThemeColors, RelativeSource={RelativeSource TemplatedParent}}"
                                         Style="{DynamicResource ColorGalleryListBox}"
                                         Padding="2" />
                                <ListBox KeyboardNavigation.DirectionalNavigation="Contained"
                                         x:Name="PART_ThemeGradientColorsListBox"
                                         ItemsSource="{Binding ThemeGradients, RelativeSource={RelativeSource TemplatedParent}}"
                                         Style="{DynamicResource ColorGalleryGradientListBox}"
                                         Padding="2,0,2,0" />
                                <Fluent:GroupSeparatorMenuItem Header="Standard Colors"
                                                               x:Name="standardColorsSeparator" />
                                <ListBox KeyboardNavigation.DirectionalNavigation="Contained"
                                         x:Name="PART_StandardColorsListBox"
                                         ItemsSource="{x:Static Fluent:ColorGallery.StandardThemeColors}"
                                         Style="{DynamicResource ColorGalleryListBox}"
                                         Padding="2" />
                                <ListBox KeyboardNavigation.DirectionalNavigation="Contained"
                                         x:Name="PART_StandardGradientColorsListBox"
                                         ItemsSource="{Binding StandardGradients, RelativeSource={RelativeSource TemplatedParent}}"
                                         Style="{DynamicResource ColorGalleryGradientListBox}"
                                         Padding="2,0,2,0" />
                                <Fluent:GroupSeparatorMenuItem Header="Recent Colors"
                                                               x:Name="recentColorsSeparator" />
                                <ListBox KeyboardNavigation.DirectionalNavigation="Contained"
                                         x:Name="PART_RecentColorsListBox"
                                         ItemsSource="{x:Static Fluent:ColorGallery.RecentColors}"
                                         Style="{DynamicResource ColorGalleryListBox}"
                                         Padding="2" />
                            </StackPanel>
                        </ScrollViewer>
                        <Fluent:MenuItem x:Name="PART_NoColor"
                                         Header="{Binding Source={x:Static Fluent:RibbonLocalization.Current}, Path=Localization.NoColor, Mode=OneWay}">
                            <Fluent:MenuItem.Icon>
                                <Rectangle Width="16"
                                           Height="16"
                                           Stroke="{DynamicResource Fluent.Ribbon.Brushes.ColorGallery.Item.BorderBrush}"
                                           Fill="Transparent"
                                           Margin="-2,0,0,0" />
                            </Fluent:MenuItem.Icon>
                        </Fluent:MenuItem>
                        <Separator x:Name="separator">
                            <Separator.Template>
                                <ControlTemplate>
                                    <Rectangle Width="Auto"
                                               Height="1"
                                               Fill="{DynamicResource Fluent.Ribbon.Brushes.Separator.Background}" />
                                </ControlTemplate>
                            </Separator.Template>
                        </Separator>
                        <Fluent:MenuItem x:Name="PART_MoreColors"
                                         Header="{Binding Source={x:Static Fluent:RibbonLocalization.Current}, Path=Localization.MoreColors, Mode=OneWay}"
                                         Icon="{DynamicResource Fluent.Ribbon.Images.MoreColors}" />
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsAutomaticColorButtonVisible"
                                 Value="False">
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_AutomaticColor" />
                        </Trigger>
                        <Trigger Property="IsNoColorButtonVisible"
                                 Value="False">
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_NoColor" />
                        </Trigger>
                        <Trigger Property="IsMoreColorsButtonVisible"
                                 Value="False">
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_MoreColors" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="separator" />
                        </Trigger>
                        <Trigger Property="Mode"
                                 Value="HighlightColors">
                            <Setter Property="ChipWidth"
                                    Value="26" />
                            <Setter Property="ChipHeight"
                                    Value="26" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="themeColorsSeparator" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="standardColorsSeparator" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="recentColorsSeparator" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_ThemeColorsListBox" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_RecentColorsListBox" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_StandardGradientColorsListBox" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_ThemeGradientColorsListBox" />
                            <Setter Property="Columns"
                                    Value="5" />
                            <Setter Property="Style"
                                    Value="{DynamicResource HightlightColorGalleryListBox}"
                                    TargetName="PART_StandardColorsListBox" />
                            <Setter Property="ItemsSource"
                                    Value="{x:Static Fluent:ColorGallery.HighlightColors}"
                                    TargetName="PART_StandardColorsListBox" />
                        </Trigger>
                        <Trigger Property="Mode"
                                 Value="StandardColors">
                            <Setter Property="ChipWidth"
                                    Value="20" />
                            <Setter Property="ChipHeight"
                                    Value="20" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="themeColorsSeparator" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="standardColorsSeparator" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="recentColorsSeparator" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_ThemeColorsListBox" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_RecentColorsListBox" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_StandardColorsListBox" />
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="PART_ThemeGradientColorsListBox" />
                            <Setter Property="Columns"
                                    Value="5" />
                            <Setter Property="StandardColorGridRows"
                                    Value="6" />
                            <Setter Property="ItemsSource"
                                    Value="{x:Static Fluent:ColorGallery.StandardColors}"
                                    TargetName="PART_StandardGradientColorsListBox" />
                        </Trigger>
                        <DataTrigger Binding="{Binding ThemeColors.Count, RelativeSource={RelativeSource Self}}"
                                     Value="0">
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="themeColorsSeparator" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Count, Source={x:Static Fluent:ColorGallery.RecentColors}}"
                                     Value="0">
                            <Setter Property="Visibility"
                                    Value="Collapsed"
                                    TargetName="recentColorsSeparator" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>