<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:AIStudio.Wpf.Mind.Controls"
                    xmlns:dd="https://gitee.com/akwkevin/aistudio.-wpf.-diagram">

    <dd:ColorBrushConverter x:Key="ColorToSolidColorBrushConverter" />
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

    <DrawingBrush  x:Key="CheckerBrush" Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <GeometryDrawing Brush="White">
                    <GeometryDrawing.Geometry>
                        <RectangleGeometry Rect="0,0 100,100" />
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
                <GeometryDrawing Brush="LightGray">
                    <GeometryDrawing.Geometry>
                        <GeometryGroup>
                            <RectangleGeometry Rect="0,0 50,50" />
                            <RectangleGeometry Rect="50,50 50,50" />
                        </GeometryGroup>
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>

    <SolidColorBrush x:Key="HorizontalSliderTrackNormalBackground"
                    Color="#FFE7EAEA" />

    <LinearGradientBrush x:Key="HorizontalSliderTrackNormalBorder"
                        EndPoint="0,1"
                        StartPoint="0,0">
        <GradientStop Color="#FFAEB1AF"
                    Offset="0.1" />
        <GradientStop Color="White"
                    Offset=".9" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ThumbStroke"
                        EndPoint="0.5,1"
                        StartPoint="0.5,0">
        <GradientStop Color="#FFA3AEB9"
                    Offset="0" />
        <GradientStop Color="#FF8399A9"
                    Offset="0.375" />
        <GradientStop Color="#FF718597"
                    Offset="0.375" />
        <GradientStop Color="#FF617584"
                    Offset="1" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="ThumbFill"
                        StartPoint="0,0"
                        EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Offset="0"
                          Color="#FFfefefe" />
                <GradientStop Offset="0.5"
                          Color="#FFeff1f2" />
                <GradientStop Offset="1"
                          Color="#FFd0d6db" />
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="ThumbMouseOver"
                    Color="#FFE5F2F6" />

    <Style x:Key="ColorCanvasTextBoxStyle"
          TargetType="TextBox"
          BasedOn="{StaticResource {x:Type TextBox}}">
        <Setter Property="Background"
              Value="Transparent" />
        <Style.Triggers>
            <Trigger Property="IsFocused" Value="False">
                <Setter Property="BorderBrush" Value="Transparent" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="SliderRepeatButtonStyle"
          TargetType="{x:Type RepeatButton}">
        <Setter Property="OverridesDefaultStyle"
              Value="true" />
        <Setter Property="IsTabStop"
              Value="false" />
        <Setter Property="Focusable"
              Value="false" />
        <Setter Property="Background"
              Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="{TemplateBinding Background}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="CustomThumbForSlider"
          TargetType="{x:Type Thumb}">
        <Setter Property="OverridesDefaultStyle"
              Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Rectangle x:Name="_thumb"
                          Fill="{StaticResource ThumbFill}"
                          Stroke="{StaticResource ThumbStroke}"
                          Height="14"
                          Width="8"
                          RadiusX="1"
                          RadiusY="1" />
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver"
                           Value="True">
                            <Setter TargetName="_thumb" Property="Rectangle.Fill" Value="{StaticResource ThumbMouseOver}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="VerticalSlideThumbStyle"
          TargetType="{x:Type Thumb}">
        <Setter Property="Focusable"
              Value="false" />
        <Setter Property="OverridesDefaultStyle"
              Value="true" />
        <Setter Property="Height"
              Value="12" />
        <Setter Property="Width"
              Value="11" />
        <Setter Property="Foreground"
              Value="Gray" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Canvas SnapsToDevicePixels="true">
                        <Path x:Name="LeftArrow"
                            Stretch="Fill"
                            StrokeLineJoin="Round"
                            Stroke="#FF000000"
                            Fill="#FF000000"
                            Data="F1 M 276.761,316L 262.619,307.835L 262.619,324.165L 276.761,316 Z "
                            RenderTransformOrigin="0.5,0.5"
                            Width="6"
                            Height="8">
                            <Path.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform />
                                    <SkewTransform />
                                    <RotateTransform />
                                    <TranslateTransform Y="6"
                                               X="-3" />
                                </TransformGroup>
                            </Path.RenderTransform>
                        </Path>
                        <Path x:Name="RightArrow"
                            Stretch="Fill"
                            StrokeLineJoin="Round"
                            Stroke="#FF000000"
                            Fill="#FF000000"
                            Data="F1 M 276.761,316L 262.619,307.835L 262.619,324.165L 276.761,316 Z "
                            RenderTransformOrigin="0.5,0.5"
                            Width="6"
                            Height="8">
                            <Path.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform />
                                    <SkewTransform />
                                    <RotateTransform Angle="-180" />
                                    <TranslateTransform Y="6"
                                               X="8" />
                                </TransformGroup>
                            </Path.RenderTransform>
                        </Path>
                    </Canvas>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ColorCanvasSliderStyle"
          TargetType="{x:Type Slider}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Slider}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                       BorderThickness="{TemplateBinding BorderThickness}"
                       Background="{TemplateBinding Background}"
                       SnapsToDevicePixels="true">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto"
                                       MinHeight="{TemplateBinding MinHeight}" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <TickBar x:Name="TopTick"
                                  Fill="{TemplateBinding Foreground}"
                                  Height="4"
                                  Placement="Top"
                                  Grid.Row="0"
                                  Visibility="Collapsed" />
                            <TickBar x:Name="BottomTick"
                                  Fill="{TemplateBinding Foreground}"
                                  Height="4"
                                  Placement="Bottom"
                                  Grid.Row="2"
                                  Visibility="Collapsed" />
                            <Border x:Name="TrackBackground"
                                 BorderBrush="{StaticResource HorizontalSliderTrackNormalBorder}"
                                 BorderThickness="1"
                                 Background="{StaticResource HorizontalSliderTrackNormalBackground}"
                                 CornerRadius="1"
                                 Height="4.0"
                                 Margin="5,0"
                                 Grid.Row="1"
                                 VerticalAlignment="center">
                                <Canvas Margin="-6,-1">
                                    <Rectangle x:Name="PART_SelectionRange"
                                      Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
                                      Height="4.0"
                                      Stroke="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"
                                      StrokeThickness="1.0"
                                      Visibility="Hidden" />
                                </Canvas>
                            </Border>
                            <Track x:Name="PART_Track" Grid.Row="1">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource SliderRepeatButtonStyle}" />
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource SliderRepeatButtonStyle}" />
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb x:Name="Thumb" Style="{StaticResource CustomThumbForSlider}" />
                                </Track.Thumb>
                            </Track>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type controls:ColorSpectrumSlider}">
        <Setter Property="BorderBrush"
              Value="DarkGray" />
        <Setter Property="BorderThickness"
              Value="1" />
        <Setter Property="Orientation"
              Value="Vertical" />
        <Setter Property="Background"
              Value="Transparent" />
        <Setter Property="Foreground"
              Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
        <Setter Property="Minimum"
              Value="0" />
        <Setter Property="Maximum"
              Value="360" />
        <Setter Property="TickFrequency"
              Value="0.001" />
        <Setter Property="IsSnapToTickEnabled"
              Value="True" />
        <Setter Property="IsDirectionReversed"
              Value="False" />
        <Setter Property="IsMoveToPointEnabled"
              Value="True" />
        <Setter Property="Value"
              Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ColorSpectrumSlider}">
                    <Grid>
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                          BorderThickness="{TemplateBinding BorderThickness}"
                          Margin="0,8,0,0">
                            <Border x:Name="PART_TrackBackground"
                             Width="15">
                                <Rectangle x:Name="PART_SpectrumDisplay"
                                   Stretch="Fill"
                                   VerticalAlignment="Stretch" />
                            </Border>
                        </Border>

                        <Track Name="PART_Track">
                            <Track.DecreaseRepeatButton>
                                <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                      Command="Slider.DecreaseLarge" />
                            </Track.DecreaseRepeatButton>
                            <Track.IncreaseRepeatButton>
                                <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}"
                                      Command="Slider.IncreaseLarge" />
                            </Track.IncreaseRepeatButton>
                            <Track.Thumb>
                                <Thumb Style="{StaticResource VerticalSlideThumbStyle}" />
                            </Track.Thumb>
                        </Track>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ColorCanvasStyle" TargetType="{x:Type controls:ColorCanvas}">
        <Setter Property="Background"
              Value="White" />
        <Setter Property="BorderBrush"
              Value="Gray" />
        <Setter Property="BorderThickness"
              Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ColorCanvas}">
                    <Border Background="{TemplateBinding Background}"
                       BorderThickness="{TemplateBinding BorderThickness}"
                       BorderBrush="{TemplateBinding BorderBrush}"
                       Padding="3">
                        <Grid Margin="2">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="200" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <Border BorderThickness="1"
                                    BorderBrush="DarkGray"
                                    ClipToBounds="True"
                                    Background="{StaticResource CheckerBrush}">
                                    <Canvas x:Name="PART_ColorShadingCanvas"
                                       Width="200"
                                       Height="100"
                                       HorizontalAlignment="Left"
                                       VerticalAlignment="Top">
                                        <Rectangle x:Name="ColorShadingRectangle"
                                             Height="{Binding ElementName=PART_ColorShadingCanvas, Path=Height}"
                                             Width="{Binding ElementName=PART_ColorShadingCanvas, Path=Width}"
                                             Fill="{Binding SelectedColor, ElementName=PART_SpectrumSlider, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
                                        <Rectangle x:Name="WhiteGradient"
                                             Width="{Binding ElementName=PART_ColorShadingCanvas,Path=Width}"
                                             Height="{Binding ElementName=PART_ColorShadingCanvas,Path=Height}">
                                            <Rectangle.Fill>
                                                <LinearGradientBrush StartPoint="0,0"
                                                         EndPoint="1,0">
                                                    <GradientStop Offset="0"
                                                     Color="#ffffffff" />
                                                    <GradientStop Offset="1"
                                                     Color="Transparent" />
                                                </LinearGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                        <Rectangle x:Name="BlackGradient"
                                             Width="{Binding ElementName=PART_ColorShadingCanvas,Path=Width}"
                                             Height="{Binding ElementName=PART_ColorShadingCanvas,Path=Height}">
                                            <Rectangle.Fill>
                                                <LinearGradientBrush StartPoint="0,1" EndPoint="0, 0">
                                                    <GradientStop Offset="0" Color="#ff000000" />
                                                    <GradientStop Offset="1" Color="#00000000" />
                                                </LinearGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                        <Canvas x:Name="PART_ColorShadeSelector"
                                      Width="10"
                                      Height="10"
                                      IsHitTestVisible="False">
                                            <Ellipse Width="10"
                                              Height="10"
                                              StrokeThickness="3"
                                              Stroke="#FFFFFFFF"
                                              IsHitTestVisible="False" />
                                            <Ellipse Width="10"
                                              Height="10"
                                              StrokeThickness="1"
                                              Stroke="#FF000000"
                                              IsHitTestVisible="False" />
                                        </Canvas>
                                    </Canvas>
                                </Border>

                                <Border Grid.Row="1"
                                Margin="0,5,0,0">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <Border x:Name="SelectedColorBorder"
                                              Background="{StaticResource CheckerBrush}"
                                              Height="22"
                                              Margin="2,0,2,0"
                                              BorderThickness="1"
                                              BorderBrush="#FFC9CACA">
                                            <Rectangle x:Name="SelectedColor"
                                            Fill="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
                                        </Border>
                                        <TextBox x:Name="PART_HexadecimalTextBox"
                                           Grid.Column="1"
                                           Margin="2,0,2,0"
                                           VerticalAlignment="Center"
                                           Style="{StaticResource ColorCanvasTextBoxStyle}" />
                                    </Grid>
                                </Border>

                                <Border Grid.Column="1" Grid.RowSpan="2" Margin="4,-8,0,0" ClipToBounds="False">
                                    <controls:ColorSpectrumSlider x:Name="PART_SpectrumSlider" VerticalAlignment="Stretch" />
                                </Border>
                            </Grid>

                            <Border x:Name="RGBBorder"
                                 MinWidth="180"
                                 Grid.Row="1"
                                 BorderThickness="1"
                                 ClipToBounds="True"
                                 Margin="0,10,0,0">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Grid.Row="0"
                                        Grid.Column="0"
                                        Text="R"
                                        VerticalAlignment="Center" />
                                    <Slider x:Name="PART_RSlider"
                                        Maximum="255"
                                        SmallChange="1"
                                        LargeChange="10"
                                        TickFrequency="1"
                                        Grid.Row="0"
                                        Grid.Column="1"
                                        Margin="4,6,4,6"
                                        Style="{StaticResource ColorCanvasSliderStyle}"
                                        Value="{Binding R, RelativeSource={RelativeSource TemplatedParent}}"
                                        VerticalAlignment="Center" />
                                    <TextBox Grid.Row="0"
                                        Grid.Column="2"
                                        Text="{Binding Value, ElementName=PART_RSlider}"
                                        VerticalAlignment="Center"
                                        Style="{StaticResource ColorCanvasTextBoxStyle}" />

                                    <TextBlock Grid.Row="1"
                                        Grid.Column="0"
                                        Text="G"
                                        VerticalAlignment="Center" />
                                    <Slider x:Name="PART_GSlider"
                                        Maximum="255"
                                        SmallChange="1"
                                        LargeChange="10"
                                        TickFrequency="1"
                                        Grid.Row="1"
                                        Grid.Column="1"
                                        Margin="4,6,4,6"
                                        Style="{StaticResource ColorCanvasSliderStyle}"
                                        Value="{Binding G, RelativeSource={RelativeSource TemplatedParent}}"
                                        VerticalAlignment="Center" />
                                    <TextBox Grid.Row="1"
                                        Grid.Column="2"
                                        Text="{Binding Value, ElementName=PART_GSlider}"
                                        VerticalAlignment="Center"
                                        Style="{StaticResource ColorCanvasTextBoxStyle}" />

                                    <TextBlock Grid.Row="2"
                                        Grid.Column="0"
                                        Text="B"
                                        VerticalAlignment="Center" />
                                    <Slider x:Name="PART_BSlider"
                                        Maximum="255"
                                        SmallChange="1"
                                        LargeChange="10"
                                        TickFrequency="1"
                                        Grid.Row="2"
                                        Grid.Column="1"
                                        Margin="4,6,4,6"
                                        Style="{StaticResource ColorCanvasSliderStyle}"
                                        Value="{Binding B, RelativeSource={RelativeSource TemplatedParent}}"
                                        VerticalAlignment="Center" />
                                    <TextBox Grid.Row="2"
                                        Grid.Column="3"
                                        Text="{Binding Value, ElementName=PART_BSlider}"
                                        VerticalAlignment="Center"
                                        Style="{StaticResource ColorCanvasTextBoxStyle}" />

                                    <TextBlock Grid.Row="3"
                                        Grid.Column="0"
                                        Text="A"
                                        VerticalAlignment="Center"
                                        Visibility="{Binding Path=UsingAlphaChannel, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                    <Slider x:Name="PART_OpacitySlider"
                                        Grid.Row="3"
                                        Grid.Column="1"
                                        Maximum="255"
                                        SmallChange="1"
                                        LargeChange="10"
                                        Margin="4,6,4,6"
                                        Style="{StaticResource ColorCanvasSliderStyle}"
                                        Value="{Binding Path=A, RelativeSource={RelativeSource TemplatedParent}}"
                                        VerticalAlignment="Center"
                                        Visibility="{Binding Path=UsingAlphaChannel, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                    <TextBox Grid.Row="3"
                                        Grid.Column="3"
                                        Text="{Binding Value, ElementName=PART_OpacitySlider}"
                                        VerticalAlignment="Center"
                                        Style="{StaticResource ColorCanvasTextBoxStyle}"
                                        Visibility="{Binding Path=UsingAlphaChannel, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToVisibilityConverter}}" />
                                </Grid>
                            </Border>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                        <Trigger Property="SelectedColor" Value="{x:Null}">
                            <Setter Property="Visibility" Value="Collapsed" TargetName="PART_ColorShadeSelector" />
                            <Setter Property="Background" Value="Transparent"  TargetName="SelectedColorBorder" />
                            <!--<Setter Property="IsEnabled" Value="False" TargetName="RGBBorder" />-->
                            <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" TargetName="RGBBorder" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style BasedOn="{StaticResource ColorCanvasStyle}" TargetType="{x:Type controls:ColorCanvas}"/>

</ResourceDictionary>
