<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:utils="clr-namespace:XamlTheme.Utils"
                    xmlns:controls="clr-namespace:XamlTheme.Controls"
                    xmlns:markup="clr-namespace:XamlTheme.Markup"
                    xmlns:themes="clr-namespace:XamlTheme">

    <ResourceDictionary.MergedDictionaries>
        <markup:SharedResourceDictionary Source="/XamlTheme;component/Styles/SliderStyle.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <utils:ColorToBrushConverter x:Key="colorToBrushConverter"/>

    <VisualBrush x:Key="{x:Static themes:ResourceKeys.AlphaVisualBrushKey}"  Stretch="None" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,12,12">
        <VisualBrush.Visual>
            <UniformGrid Rows="2" Columns="2" Width="12" Height="12">
                <Rectangle Fill="#F6F6F6"/>
                <Rectangle Fill="#CCCEDB"/>
                <Rectangle Fill="#CCCEDB"/>
                <Rectangle Fill="#F6F6F6"/>
            </UniformGrid>
        </VisualBrush.Visual>
    </VisualBrush>

    <Style TargetType="{x:Type controls:ColorPicker}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ColorPicker}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="2"/>
                                <RowDefinition Height="20"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/> 
                                <ColumnDefinition Width="2"/>
                                <ColumnDefinition Width="20"/>
                                <ColumnDefinition Width="2"/>
                                <ColumnDefinition Width="20"/>
                            </Grid.ColumnDefinitions>
                            <!--Color Selection-->
                            <Canvas x:Name="PART_ColorCanvas" ClipToBounds="True">
                                <Canvas.Background>
                                    <DrawingBrush>
                                        <DrawingBrush.Drawing>
                                            <DrawingGroup>
                                                <GeometryDrawing>
                                                    <GeometryDrawing.Brush>
                                                        <LinearGradientBrush EndPoint="1,0">
                                                            <GradientStop Color="White" Offset="0"/>
                                                            <GradientStop Color="{Binding HueColor,RelativeSource={RelativeSource TemplatedParent}}" Offset="1"/>
                                                        </LinearGradientBrush>
                                                    </GeometryDrawing.Brush>
                                                    <GeometryDrawing.Geometry>
                                                        <RectangleGeometry Rect="0,0,5,5"/>
                                                    </GeometryDrawing.Geometry>
                                                </GeometryDrawing>
                                                <GeometryDrawing>
                                                    <GeometryDrawing.Brush>
                                                        <LinearGradientBrush EndPoint="0,1">
                                                            <GradientStop Color="#00000000" Offset="0"/>
                                                            <GradientStop Color="Black" Offset="1"/>
                                                        </LinearGradientBrush>
                                                    </GeometryDrawing.Brush>
                                                    <GeometryDrawing.Geometry>
                                                        <RectangleGeometry Rect="0,0,5,5"/>
                                                    </GeometryDrawing.Geometry>
                                                </GeometryDrawing>
                                            </DrawingGroup>
                                        </DrawingBrush.Drawing>
                                    </DrawingBrush>
                                </Canvas.Background>

                                <Path x:Name="PART_SelectPath" StrokeThickness="3" Stretch="Fill" Fill="Transparent" 
                                          Width="12" Height="12" Canvas.Left="-6" Canvas.Top="-6" Data="M 10,0 A 10,10 0 1 1 9,0 z">
                                    <Path.Stroke>
                                        <RadialGradientBrush>
                                            <GradientStop Color="Transparent" Offset="0.60" />
                                            <GradientStop Color="White" Offset="0.60" />
                                            <GradientStop Color="White" Offset="0.85" />
                                            <GradientStop Color="Black" Offset="0.85" />
                                            <GradientStop Color="Black" Offset="1" />
                                        </RadialGradientBrush>
                                    </Path.Stroke>
                                </Path>
                            </Canvas>

                            <!--Hue Color Selection-->
                            <Slider x:Name="PART_HueSlider" Grid.Row="0" Grid.Column="2" Maximum="1"
                                    Style="{StaticResource ColorPickerSliderStyle}">
                                <Slider.Background>
                                    <LinearGradientBrush StartPoint="1,0">
                                        <GradientStop Color="#ff0000" Offset="0"/>
                                        <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>
                                </Slider.Background>
                            </Slider>

                            <Grid Grid.Row="0" Grid.Column="4" Width="20">
                                <Rectangle Fill="{StaticResource {x:Static themes:ResourceKeys.AlphaVisualBrushKey}}"/>
                                <Slider x:Name="PART_AlphaSlider" Maximum="255" Style="{StaticResource ColorPickerSliderStyle}">
                                    <Slider.Background>
                                        <LinearGradientBrush EndPoint="0,1">
                                            <GradientStop Color="Black" Offset="0"/>
                                            <GradientStop Color="Transparent" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Slider.Background>
                                </Slider>
                            </Grid>

                            <!--Show Selected Color-->
                            <Rectangle Grid.Row="2" Grid.Column="0" Fill="{StaticResource {x:Static themes:ResourceKeys.AlphaVisualBrushKey}}"/>
                            <Rectangle Grid.Row="2" Grid.Column="0" Fill="{TemplateBinding SelectedColor,Converter={StaticResource colorToBrushConverter}}"/>

                            <!--Show Last Color-->
                            <Rectangle Grid.Row="2" Grid.Column="2" Fill="{StaticResource {x:Static themes:ResourceKeys.AlphaVisualBrushKey}}"/>
                            <Rectangle Grid.Row="2" Grid.Column="2" Fill="{TemplateBinding LastColor,Converter={StaticResource colorToBrushConverter}}"/>

                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>