<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:themes="clr-namespace:XamlTheme"> 
 
    <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="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Rectangle Fill="Transparent"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--Normal-->
    <ControlTemplate x:Key="SliderThumbTemplate" TargetType="{x:Type Thumb}">
        <Grid>
            <Rectangle x:Name="grip" RadiusX="2" RadiusY="2" Fill="{TemplateBinding Background}" StrokeThickness="0"/>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Fill" TargetName="grip" Value="#686868"/>
            </Trigger>
            <Trigger Property="IsDragging" Value="true">
                <Setter Property="Fill" TargetName="grip" Value="#5B5B5B"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Fill" TargetName="grip" Value="LightGray"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="SliderHorizontal" TargetType="{x:Type Slider}">
        <Border x:Name="border" 
                BorderBrush="{TemplateBinding BorderBrush}" 
                BorderThickness="{TemplateBinding BorderThickness}"
                SnapsToDevicePixels="True">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Border x:Name="TrackBackground" BorderThickness="1" Background="{TemplateBinding Background}" Height="4.0" Margin="5,0" Grid.Row="1" VerticalAlignment="center">
                    <Canvas Margin="-6,0">
                        <Rectangle x:Name="PART_SelectionRange" Fill="{TemplateBinding Foreground}" Height="2.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" Height="18" Width="6"
                               Focusable="False"  OverridesDefaultStyle="True" VerticalAlignment="Center"
                               Background="{TemplateBinding Foreground}"  
                               Template="{StaticResource SliderThumbTemplate}"/>
                    </Track.Thumb>
                </Track>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSelectionRangeEnabled" Value="true">
                <Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
                <Setter Property="Foreground" TargetName="Thumb" Value="Blue"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="SliderVertical" TargetType="{x:Type Slider}">
        <Border x:Name="border" 
                BorderBrush="{TemplateBinding BorderBrush}" 
                BorderThickness="{TemplateBinding BorderThickness}"  
                SnapsToDevicePixels="True">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition MinWidth="{TemplateBinding MinWidth}" Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Border x:Name="TrackBackground" BorderThickness="1" Background="{TemplateBinding Background}" Grid.Column="1" HorizontalAlignment="center" Margin="0,5" Width="4.0">
                    <Canvas Margin="0,-6">
                        <Rectangle x:Name="PART_SelectionRange" Fill="{TemplateBinding Foreground}" Visibility="Hidden" Width="2.0"/>
                    </Canvas>
                </Border>
                <Track x:Name="PART_Track" Grid.Column="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" Width="18" Height="6"
                               Focusable="False" OverridesDefaultStyle="True" VerticalAlignment="Top"
                               Background="{TemplateBinding Foreground}"
                               Template="{StaticResource SliderThumbTemplate}"/>
                    </Track.Thumb>
                </Track>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSelectionRangeEnabled" Value="true">
                <Setter Property="Visibility" TargetName="PART_SelectionRange" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsKeyboardFocused" Value="true">
                <Setter Property="Foreground" TargetName="Thumb" Value="Blue"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="{x:Static themes:ResourceKeys.NormalSliderStyleKey}" TargetType="{x:Type Slider}">
        <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
        <Setter Property="Background" Value="#C2C3C9"/>
        <Setter Property="Foreground" Value="#007ACC"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="Template" Value="{StaticResource SliderHorizontal}"/>
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Template" Value="{StaticResource SliderVertical}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="LightGray"/>
                <Setter Property="Opacity" Value="0.5"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <!--Color Picker-->
    <ControlTemplate x:Key="ColorPickerHorizontalSliderThumb" TargetType="{x:Type Thumb}">
        <Grid SnapsToDevicePixels="true" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="6"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="6"/>
            </Grid.RowDefinitions>
            <Path Data="M0,0 H10 L5,5 Z" Stretch="Fill" StrokeThickness="1"
                  Fill="{TemplateBinding Background}"
                  Stroke="{TemplateBinding BorderBrush}"/>
            <Path Grid.Row="2" Data="M0,0 H10 L5,-5 Z" Stretch="Fill" StrokeThickness="1"
                  Fill="{TemplateBinding Background}"
                  Stroke="{TemplateBinding BorderBrush}"/>
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="ColorPickerVerticalSliderThumb" TargetType="{x:Type Thumb}">
        <Grid SnapsToDevicePixels="true" Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="6"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="6"/>
            </Grid.ColumnDefinitions>
            <Path Data="M0,0 V10 L5,5 Z" Stretch="Fill" StrokeThickness="1"
                  Fill="{TemplateBinding Background}"
                  Stroke="{TemplateBinding BorderBrush}"/>
            <Path Grid.Column="2" Data="M0,0 V10 L-5,5 Z" Stretch="Fill" StrokeThickness="1"
                  Fill="{TemplateBinding Background}"
                  Stroke="{TemplateBinding BorderBrush}"/>
        </Grid>
    </ControlTemplate>

    <Style x:Key="ColorPickerSliderStyle" TargetType="{x:Type Slider}">
        <Setter Property="Background" Value="LightGray"/>
        <Setter Property="BorderBrush" Value="Black"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="IsMoveToPointEnabled" Value="true"/>
        <Setter Property="Orientation" Value="Vertical"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Slider">
                    <Grid SnapsToDevicePixels="true" ClipToBounds="true">
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}"/>
                        <Track x:Name="PART_Track" Margin="0,-5">
                            <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" Focusable="false" Height="10" Background="Black" BorderBrush="White"
                                       Template="{StaticResource ColorPickerVerticalSliderThumb}"/>
                            </Track.Thumb>
                        </Track>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Orientation" Value="Horizontal">
                            <Setter Property="Template" TargetName="thumb" Value="{StaticResource ColorPickerHorizontalSliderThumb}"/>
                            <Setter Property="Height" TargetName="thumb" Value="auto"/>
                            <Setter Property="Width" TargetName="thumb" Value="10"/>
                            <Setter Property="Margin" TargetName="PART_Track" Value="-5,0"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>