<UserControl
    x:Class="PDF_Office.CustomControl.CompositeControl.ColorContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convert="clr-namespace:PDF_Office.DataConvert"
    xmlns:cus="clr-namespace:PDF_Office.CustomControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:PDF_Office.CustomControl.CompositeControl"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Styles/CustomBtnStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <convert:ColorBrushConvert x:Key="colorBrushConvert" />
            <DataTemplate x:Key="listboxData">
                <Ellipse
                    Width="20"
                    Height="20"
                    Fill="{Binding Color}" />
            </DataTemplate>

            <ContextMenu x:Key="FlyoutMenu" FontSize="14">
                <ContextMenu.ItemContainerStyle>
                    <Style TargetType="MenuItem">
                        <Setter Property="Padding" Value="0,7,0,7" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                    </Style>
                </ContextMenu.ItemContainerStyle>
                <MenuItem
                    Name="ChangeColorMenuItem"
                    Click="ChangeColorMenuItem_Click"
                    Header="更改颜色"
                    IsEnabled="True" />
                <MenuItem
                    Name="BackColorMenuItem"
                    Click="BackColorMenuItem_Click"
                    Header="恢复默认颜色"
                    IsEnabled="True" />
            </ContextMenu>

            <Style x:Key="listboxItemStyle" TargetType="{x:Type ListBoxItem}">
                <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}" />
                <Setter Property="HorizontalContentAlignment" Value="Center" />
                <Setter Property="Height" Value="32" />
                <Setter Property="Margin" Value="2,0,2,0" />
                <EventSetter Event="PreviewMouseRightButtonDown" Handler="listboxItem_PreviewMouseRightButtonDown" />
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
        <Border
            Grid.Column="1"
            Width="56"
            Height="32"
            Margin="0,0,5,0"
            HorizontalAlignment="Right"
            BorderBrush="#E2E3E6"
            BorderThickness="1"
            CornerRadius="4">
            <StackPanel Orientation="Horizontal">

                <Ellipse
                    x:Name="ElcustomColor"
                    Width="20"
                    Height="20"
                    Margin="4,0"
                    Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=SelectedColor, Converter={StaticResource colorBrushConvert}}"
                    PreviewMouseLeftButtonDown="ElcustomColor_PreviewMouseLeftButtonDown" />
                <cus:ColorDropBox
                    x:Name="ColorDropPicker"
                    Margin="4,0"
                    SelectedColorChanged="ColorDropPicker_SelectedColorChanged" />
            </StackPanel>
        </Border>
        <cus:ColorDropBox
            x:Name="PnlColor"
            Opacity="0"
            SelectedColorChanged="PnlColor_SelectedColorChanged"
            Visibility="{Binding ElementName=ListColor, Path=Visibility}" />

        <ListBox
            x:Name="ListColor"
            Background="Transparent"
            BorderThickness="0"
            ItemContainerStyle="{StaticResource listboxItemStyle}"
            ItemTemplate="{StaticResource listboxData}"
            SelectionChanged="ListColor_SelectionChanged"
            Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:ColorContent}, Path=ShowColorList}">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </Grid>
</UserControl>
