<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:langs="clr-namespace:HandyControl.Properties.Langs"
                    xmlns:controls="clr-namespace:HandyControl.Controls"
                    xmlns:interactivity="clr-namespace:HandyControl.Interactivity">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="../../Basic/Paths.xaml"/>
        <ResourceDictionary Source="../../Basic/Converters.xaml"/>
        <ResourceDictionary Source="../Slider.xaml"/>
        <ResourceDictionary Source="../Button.xaml"/>
        <ResourceDictionary Source="../ToggleButton.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="ColorPickerSliderRepeatButtonBaseStyle" TargetType="RepeatButton">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RepeatButton">
                    <Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="ColorPickerSliderThumbTemplate" TargetType="Thumb">
        <Border Width="13" Height="13" Background="White" CornerRadius="6.5"/>
    </ControlTemplate>

    <ControlTemplate x:Key="ColorPickerSliderHorizontal" TargetType="Slider">
        <controls:SimplePanel>
            <Border Margin="7,0" Background="{TemplateBinding Background}" MaxHeight="11" CornerRadius="2"/>
            <Border Margin="7,0" Background="{TemplateBinding Foreground}" MaxHeight="11" CornerRadius="2">
                <Border.OpacityMask>
                    <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,0.5">
                        <GradientStop Color="Transparent" Offset="1"/>
                        <GradientStop Color="White" Offset="0"/>
                    </LinearGradientBrush>
                </Border.OpacityMask>
            </Border>
            <Track x:Name="PART_Track">
                <Track.DecreaseRepeatButton>
                    <RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource ColorPickerSliderRepeatButtonBaseStyle}"/>
                </Track.DecreaseRepeatButton>
                <Track.IncreaseRepeatButton>
                    <RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource ColorPickerSliderRepeatButtonBaseStyle}"/>
                </Track.IncreaseRepeatButton>
                <Track.Thumb>
                    <Thumb x:Name="Thumb" Focusable="False" Height="13" Width="13" OverridesDefaultStyle="True" Template="{StaticResource ColorPickerSliderThumbTemplate}" VerticalAlignment="Center">
                        <Thumb.Effect>
                            <DropShadowEffect ShadowDepth="0" Opacity=".6"/>
                        </Thumb.Effect>
                    </Thumb>
                </Track.Thumb>
            </Track>
        </controls:SimplePanel>
    </ControlTemplate>

    <ControlTemplate x:Key="ColorPickerSliderVertical" TargetType="Slider">
        <controls:SimplePanel>
            <Border Margin="0,7" CornerRadius="2" MaxWidth="11" Background="{TemplateBinding Background}"/>
            <Border Margin="0,7" CornerRadius="2" MaxWidth="11" Background="{TemplateBinding Foreground}">
                <Border.OpacityMask>
                    <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,0.5">
                        <GradientStop Color="Transparent" Offset="1"/>
                        <GradientStop Color="White" Offset="0"/>
                    </LinearGradientBrush>
                </Border.OpacityMask>
            </Border>
            <Track x:Name="PART_Track">
                <Track.DecreaseRepeatButton>
                    <RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource ColorPickerSliderRepeatButtonBaseStyle}"/>
                </Track.DecreaseRepeatButton>
                <Track.IncreaseRepeatButton>
                    <RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource ColorPickerSliderRepeatButtonBaseStyle}"/>
                </Track.IncreaseRepeatButton>
                <Track.Thumb>
                    <Thumb x:Name="Thumb" Focusable="False" Height="13" OverridesDefaultStyle="True" Template="{StaticResource ColorPickerSliderThumbTemplate}" VerticalAlignment="Top" Width="13">
                        <Thumb.Effect>
                            <DropShadowEffect ShadowDepth="0" Opacity=".6"/>
                        </Thumb.Effect>
                    </Thumb>
                </Track.Thumb>
            </Track>
        </controls:SimplePanel>
    </ControlTemplate>

    <Style x:Key="ColorPickerSlider" BasedOn="{StaticResource BaseStyle}" TargetType="Slider">
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="Foreground" Value="Transparent"/>
        <Setter Property="Template" Value="{StaticResource ColorPickerSliderHorizontal}"/>
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Template" Value="{StaticResource ColorPickerSliderVertical}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <LinearGradientBrush x:Key="ColorPickerRainbowBrush">
        <GradientStop Color="#ff0000"/>
        <GradientStop Color="#ff00ff" Offset="0.167"/>
        <GradientStop Color="#0000ff" Offset="0.334"/>
        <GradientStop Color="#00ffff" Offset="0.501"/>
        <GradientStop Color="#00ff00" Offset="0.668"/>
        <GradientStop Color="#ffff00" Offset="0.835"/>
        <GradientStop Color="#ff0000" Offset="1"/>
    </LinearGradientBrush>

    <DrawingBrush x:Key="ColorPickerOpacityBrush" Viewport="0,0,12,11" ViewportUnits="Absolute" Stretch="None" TileMode="Tile">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <GeometryDrawing Brush="#d0cec7">
                    <GeometryDrawing.Geometry>
                        <GeometryGroup>
                            <RectangleGeometry Rect="0,0,6,5" />
                            <RectangleGeometry Rect="6,6,6,5" />
                        </GeometryGroup>
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
                <GeometryDrawing Brush="#e7e7e2">
                    <GeometryDrawing.Geometry>
                        <RectangleGeometry Rect="0,5,12,1" />
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>

    <Style x:Key="ColorPickerBaseStyle" TargetType="controls:ColorPicker">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Width" Value="230"/>
        <Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
        <Setter Property="UseLayoutRounding" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:ColorPicker">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="122"/>
                            <RowDefinition Height="110"/>
                            <RowDefinition Height="62"/>
                            <RowDefinition Height="62"/>
                        </Grid.RowDefinitions>
                        <Border BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Grid.RowSpan="4" Background="{TemplateBinding Background}"/>
                        <controls:SimplePanel Margin="1" Grid.Row="0">
                            <Border Background="{TemplateBinding BackColor}"/>
                            <Border>
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,0.5">
                                        <GradientStop Color="White" Offset="1"/>
                                        <GradientStop Color="#80ffffff" Offset=".5"/>
                                        <GradientStop Color="#00ffffff"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <Border>
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="Black" Offset="1"/>
                                        <GradientStop Color="#80000000" Offset=".5"/>
                                        <GradientStop Color="#00000000"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                        </controls:SimplePanel>
                        <Border Name="PART_BorderColor" Grid.Row="0" CornerRadius="2,2,0,0" ClipToBounds="True">
                            <Canvas Margin="-6">
                                <Border Name="PART_BorderPicker" Background="Transparent" Height="12" CornerRadius="6" Width="12" BorderThickness="1" BorderBrush="White">
                                    <Border.Effect>
                                        <DropShadowEffect ShadowDepth="0" Opacity=".4"/>
                                    </Border.Effect>
                                </Border>
                            </Canvas>
                        </Border>
                        <Border Grid.Row="0" Background="Transparent" Name="PART_BorderDrag"/>
                        <Grid Margin="16,16,10,0" Grid.Row="1">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="28"/>
                            </Grid.ColumnDefinitions>
                            <ToggleButton Name="PART_ButtonDropper" Width="16" Height="16" Margin="0,0,10,0" Style="{StaticResource ToggleButtonCustom}" controls:StatusSwitchElement.HideUncheckedElement="True">
                                <Path Data="{StaticResource DropperGeometry}" Fill="{DynamicResource PrimaryTextBrush}"/>
                                <controls:StatusSwitchElement.CheckedElement>
                                    <Path Data="{StaticResource DropperGeometry}" Fill="{DynamicResource DarkPrimaryBrush}"/>
                                </controls:StatusSwitchElement.CheckedElement>
                            </ToggleButton>
                            <Border Grid.Row="0" Grid.Column="1" Width="32" Height="32" CornerRadius="16" Background="{StaticResource ColorPickerOpacityBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"/>
                            <Border Grid.Row="0" Grid.Column="1" Width="32" Height="32" CornerRadius="16" Background="{TemplateBinding SelectedBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1"/>
                            <Slider Name="PART_SliderColor" LargeChange="0.01" SmallChange="0.01" Grid.ColumnSpan="2" Value="6" Maximum="6" Background="{StaticResource ColorPickerRainbowBrush}" Margin="2,1,0,0" Grid.Row="0" Grid.Column="2" VerticalAlignment="Top" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"/>
                            <Slider Name="PART_SliderOpacity" Grid.ColumnSpan="2" IsSnapToTickEnabled="True" Value="{Binding ChannelA,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" Maximum="255" SmallChange="1" Foreground="{TemplateBinding SelectedBrushWithoutOpacity}" Background="{StaticResource ColorPickerOpacityBrush}" Margin="2,0,0,0" Grid.Row="0" Grid.Column="2" VerticalAlignment="Bottom" Style="{StaticResource ColorPickerSlider}" IsMoveToPointEnabled="True"/>
                            <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,14,0,0" VerticalAlignment="Top" Visibility="{Binding ShowList[0],RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}">
                                <TextBox Padding="0" HorizontalContentAlignment="Center" Width="176" Text="{Binding SelectedBrush,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay,Converter={StaticResource Color2HexStrConverter},UpdateSourceTrigger=LostFocus}" FontSize="10" MaxLength="10" Height="24" />
                                <TextBlock Foreground="{DynamicResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="HEX" HorizontalAlignment="Center"/>
                            </StackPanel>
                            <UniformGrid Name="PART_PanelRgb" Visibility="{Binding ShowList[1],RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Rows="1" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="-2,14,-2,0" VerticalAlignment="Top">
                                <StackPanel Margin="2,0">
                                    <controls:NumericUpDown HorizontalContentAlignment="Center" Padding="2,0" Tag="R" Value="{Binding ChannelR,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" ShowUpDownButton="False" Maximum="255" Minimum="0" FontSize="10" Height="24" />
                                    <TextBlock Foreground="{DynamicResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="R" HorizontalAlignment="Center"/>
                                </StackPanel>
                                <StackPanel Margin="2,0">
                                    <controls:NumericUpDown HorizontalContentAlignment="Center" Padding="0" Tag="G" Value="{Binding ChannelG,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" ShowUpDownButton="False" Maximum="255" Minimum="0" FontSize="10" Height="24" />
                                    <TextBlock Foreground="{DynamicResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="G" HorizontalAlignment="Center"/>
                                </StackPanel>
                                <StackPanel Margin="2,0">
                                    <controls:NumericUpDown HorizontalContentAlignment="Center" Padding="0" Tag="B" Value="{Binding ChannelB,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}" ShowUpDownButton="False" Maximum="255" Minimum="0" FontSize="10" Height="24" />
                                    <TextBlock Foreground="{DynamicResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="B" HorizontalAlignment="Center"/>
                                </StackPanel>
                                <StackPanel Margin="2,0">
                                    <controls:NumericUpDown HorizontalContentAlignment="Center" Padding="0" Value="{Binding ChannelA,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ShowUpDownButton="False" Maximum="255" Minimum="0" FontSize="10" Height="24" />
                                    <TextBlock Foreground="{DynamicResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="A" HorizontalAlignment="Center"/>
                                </StackPanel>
                            </UniformGrid>
                            <Button Command="interactivity:ControlCommands.Switch" Padding="6" FontSize="8" BorderThickness="0" HorizontalAlignment="Right" Height="24" Width="20" Grid.Column="3" Grid.Row="1">
                                <Button.Content>
                                    <Path Fill="#323534" Style="{StaticResource UpDownPathStyle}"/>
                                </Button.Content>
                            </Button>
                        </Grid>
                        <Border Grid.Row="2" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
                            <WrapPanel Name="PART_PanelColor" Margin="6" HorizontalAlignment="Center"/>
                        </Border>
                        <Border Grid.Row="3" BorderThickness="0,1,0,0" BorderBrush="{DynamicResource BorderBrush}">
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                                <Button Command="interactivity:ControlCommands.Cancel" Content="{x:Static langs:Lang.Cancel}" Width="80" Margin="0,0,16,0"/>
                                <Button Command="interactivity:ControlCommands.Confirm" Content="{x:Static langs:Lang.Confirm}" Width="80" Style="{StaticResource ButtonPrimary}"/>
                            </StackPanel>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>