Browse Source

ColorPicker: completely re-wrote the color picker control. It now no longer has the color canvas and sliders to choose colors, (it will eventually in advanced mode). It now has 140 color squares of all available KnownColors, it also has a standard color palette of ten commonly used colors, and keeps track of recently used colors. You can supply your own custom available color and standard color palettes by setting the AvailableColors and StandardColors properties.

pull/1645/head
brianlagunas_cp 16 years ago
parent
commit
d8d4a632b9
  1. 17
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorItem.cs
  2. 379
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs
  3. 85
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorSpectrumSlider.cs
  4. 156
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorUtilities.cs
  5. 18
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/HsvColor.cs
  6. 364
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml
  7. 6
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

17
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorItem.cs

@ -0,0 +1,17 @@
using System;
using System.Windows.Media;
namespace Microsoft.Windows.Controls
{
public class ColorItem
{
public Color Color { get; set; }
public string Name { get; set; }
public ColorItem(Color color, string name)
{
Color = color;
Name = name;
}
}
}

379
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorPicker.cs

@ -1,238 +1,98 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Controls.Primitives;
using System.Collections.ObjectModel;
using System.Reflection;
namespace Microsoft.Windows.Controls
{
public class ColorPicker : Control
{
#region Private Members
#region Members
ToggleButton _colorPickerToggleButton;
Popup _colorPickerCanvasPopup;
Button _okButton;
private TranslateTransform _colorShadeSelectorTransform = new TranslateTransform();
private Canvas _colorShadingCanvas;
private Canvas _colorShadeSelector;
private ColorSpectrumSlider _spectrumSlider;
private Point? _currentColorPosition;
private Color _currentColor = Colors.White;
private bool _isLoaded;
ListBox _availableColors;
ListBox _standardColors;
ListBox _recentColors;
#endregion //Private Members
#endregion //Members
#region Constructors
#region Properties
static ColorPicker()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorPicker), new FrameworkPropertyMetadata(typeof(ColorPicker)));
}
#region AvailableColors
public ColorPicker()
public static readonly DependencyProperty AvailableColorsProperty = DependencyProperty.Register("AvailableColors", typeof(ObservableCollection<ColorItem>), typeof(ColorPicker), new UIPropertyMetadata(CreateAvailableColors()));
public ObservableCollection<ColorItem> AvailableColors
{
get { return (ObservableCollection<ColorItem>)GetValue(AvailableColorsProperty); }
set { SetValue(AvailableColorsProperty, value); }
}
#endregion //Constructors
#endregion //AvailableColors
#region Properties
#region RecenColors
public static readonly DependencyProperty CurrentColorProperty = DependencyProperty.Register("CurrentColor", typeof(Color), typeof(ColorPicker), new PropertyMetadata(Colors.White));
public Color CurrentColor
public static readonly DependencyProperty RecentColorsProperty = DependencyProperty.Register("RecentColors", typeof(ObservableCollection<ColorItem>), typeof(ColorPicker), new UIPropertyMetadata(null));
public ObservableCollection<ColorItem> RecentColors
{
get { return (Color)GetValue(CurrentColorProperty); }
set { SetValue(CurrentColorProperty, value); }
get { return (ObservableCollection<ColorItem>)GetValue(RecentColorsProperty); }
set { SetValue(RecentColorsProperty, value); }
}
#endregion //RecentColors
#region SelectedColor
public static readonly DependencyProperty SelectedColorProperty = DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorPicker), new FrameworkPropertyMetadata(Colors.White, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(SelectedColorPropertyChanged)));
public static readonly DependencyProperty SelectedColorProperty = DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorPicker), new FrameworkPropertyMetadata(Colors.White, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnSelectedColorPropertyChanged)));
public Color SelectedColor
{
get { return (Color)GetValue(SelectedColorProperty); }
set { SetValue(SelectedColorProperty, value); }
}
private static void SelectedColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void OnSelectedColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ColorPicker colorPicker = (ColorPicker)d;
colorPicker.SetSelectedColor((Color)e.NewValue);
}
#endregion //SelectedColor
#region ScRGB
#region ScA
public static readonly DependencyProperty ScAProperty = DependencyProperty.Register("ScA", typeof(float), typeof(ColorPicker), new PropertyMetadata((float)1, new PropertyChangedCallback(OnScAPropertyChangedChanged)));
public float ScA
{
get { return (float)GetValue(ScAProperty); }
set { SetValue(ScAProperty, value); }
}
private static void OnScAPropertyChangedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ColorPicker c = (ColorPicker)d;
c.SetScA((float)e.NewValue);
}
protected virtual void SetScA(float newValue)
{
_currentColor.ScA = newValue;
A = _currentColor.A;
CurrentColor = _currentColor;
HexadecimalString = _currentColor.ToString();
}
#endregion //ScA
#region ScR
public static readonly DependencyProperty ScRProperty = DependencyProperty.Register("ScR", typeof(float), typeof(ColorPicker), new PropertyMetadata((float)1, new PropertyChangedCallback(OnScRPropertyChanged)));
public float ScR
{
get { return (float)GetValue(ScRProperty); }
set { SetValue(RProperty, value); }
}
private static void OnScRPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
#endregion //ScR
#region ScG
public static readonly DependencyProperty ScGProperty = DependencyProperty.Register("ScG", typeof(float), typeof(ColorPicker), new PropertyMetadata((float)1, new PropertyChangedCallback(OnScGPropertyChanged)));
public float ScG
{
get { return (float)GetValue(ScGProperty); }
set { SetValue(GProperty, value); }
}
private static void OnScGPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
#endregion //ScG
#region ScB
public static readonly DependencyProperty ScBProperty = DependencyProperty.Register("ScB", typeof(float), typeof(ColorPicker), new PropertyMetadata((float)1, new PropertyChangedCallback(OnScBPropertyChanged)));
public float ScB
{
get { return (float)GetValue(BProperty); }
set { SetValue(BProperty, value); }
}
private static void OnScBPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (colorPicker != null)
colorPicker.SelectedColorChanged((Color)e.OldValue, (Color)e.NewValue);
}
#endregion //ScB
#endregion //ScRGB
#region RGB
#region A
public static readonly DependencyProperty AProperty = DependencyProperty.Register("A", typeof(byte), typeof(ColorPicker), new PropertyMetadata((byte)255, new PropertyChangedCallback(OnAPropertyChanged)));
public byte A
private void SelectedColorChanged(Color oldValue, Color newValue)
{
get { return (byte)GetValue(AProperty); }
set { SetValue(AProperty, value); }
}
private static void OnAPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ColorPicker c = (ColorPicker)d;
c.SetA((byte)e.NewValue);
}
protected virtual void SetA(byte newValue)
{
_currentColor.A = newValue;
SetValue(CurrentColorProperty, _currentColor);
}
#endregion //A
#region R
public static readonly DependencyProperty RProperty = DependencyProperty.Register("R", typeof(byte), typeof(ColorPicker), new PropertyMetadata((byte)255, new PropertyChangedCallback(OnRPropertyChanged)));
public byte R
{
get { return (byte)GetValue(RProperty); }
set { SetValue(RProperty, value); }
}
private static void OnRPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
#endregion //R
#region G
public static readonly DependencyProperty GProperty = DependencyProperty.Register("G", typeof(byte), typeof(ColorPicker), new PropertyMetadata((byte)255, new PropertyChangedCallback(OnGPropertyChanged)));
public byte G
{
get { return (byte)GetValue(GProperty); }
set { SetValue(GProperty, value); }
}
private static void OnGPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
#endregion //G
#region B
#endregion //SelectedColor
public static readonly DependencyProperty BProperty = DependencyProperty.Register("B", typeof(byte), typeof(ColorPicker), new PropertyMetadata((byte)255, new PropertyChangedCallback(OnBPropertyChanged)));
public byte B
{
get { return (byte)GetValue(BProperty); }
set { SetValue(BProperty, value); }
}
#region StandardColors
private static void OnBPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
public static readonly DependencyProperty StandardColorsProperty = DependencyProperty.Register("StandardColors", typeof(ObservableCollection<ColorItem>), typeof(ColorPicker), new UIPropertyMetadata(CreateStandardColors()));
public ObservableCollection<ColorItem> StandardColors
{
get { return (ObservableCollection<ColorItem>)GetValue(StandardColorsProperty); }
set { SetValue(StandardColorsProperty, value); }
}
#endregion //B
#endregion //StandardColors
#endregion //RGB
#endregion //Properties
#region HexadecimalString
#region Constructors
public static readonly DependencyProperty HexadecimalStringProperty = DependencyProperty.Register("HexadecimalString", typeof(string), typeof(ColorPicker), new PropertyMetadata("#FFFFFFFF", new PropertyChangedCallback(OnHexadecimalStringPropertyChanged)));
public string HexadecimalString
static ColorPicker()
{
get { return (string)GetValue(HexadecimalStringProperty); }
set { SetValue(HexadecimalStringProperty, value); }
DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorPicker), new FrameworkPropertyMetadata(typeof(ColorPicker)));
}
private static void OnHexadecimalStringPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
public ColorPicker()
{
RecentColors = new ObservableCollection<ColorItem>();
}
#endregion //HexadecimalString
#endregion //Properties
#endregion //Constructors
#region Base Class Overrides
@ -243,81 +103,41 @@ namespace Microsoft.Windows.Controls
_colorPickerToggleButton = (ToggleButton)GetTemplateChild("PART_ColorPickerToggleButton");
_colorPickerToggleButton.Click += ColorPickerToggleButton_Clicked;
_colorPickerCanvasPopup = (Popup)GetTemplateChild("PART_ColorPickerCanvasPopup");
_colorShadingCanvas = (Canvas)GetTemplateChild("PART_ColorShadingCanvas");
_colorShadingCanvas.MouseLeftButtonDown += ColorShadingCanvas_MouseLeftButtonDown;
_colorShadingCanvas.MouseMove += ColorShadingCanvas_MouseMove;
_colorShadingCanvas.SizeChanged += ColorShadingCanvas_SizeChanged;
_colorPickerCanvasPopup = (Popup)GetTemplateChild("PART_ColorPickerPalettePopup");
_colorShadeSelector = (Canvas)GetTemplateChild("PART_ColorShadeSelector");
_colorShadeSelector.RenderTransform = _colorShadeSelectorTransform;
_availableColors = (ListBox)GetTemplateChild("PART_AvailableColors");
_availableColors.SelectionChanged += Color_SelectionChanged;
_spectrumSlider = (ColorSpectrumSlider)GetTemplateChild("PART_SpectrumSlider");
_spectrumSlider.ValueChanged += SpectrumSlider_ValueChanged;
_standardColors = (ListBox)GetTemplateChild("PART_StandardColors");
_standardColors.SelectionChanged += Color_SelectionChanged;
_okButton = (Button)GetTemplateChild("PART_OkButton");
_okButton.Click += OkButton_Click;
SetSelectedColor(SelectedColor);
_recentColors = (ListBox)GetTemplateChild("PART_RecentColors");
_recentColors.SelectionChanged += Color_SelectionChanged;
}
#endregion //Base Class Overrides
#region Event Handlers
void ColorShadingCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point p = e.GetPosition(_colorShadingCanvas);
UpdateColorShadeSelectorPositionAndCalculateColor(p, true);
}
void ColorShadingCanvas_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point p = e.GetPosition(_colorShadingCanvas);
UpdateColorShadeSelectorPositionAndCalculateColor(p, true);
Mouse.Synchronize();
}
}
void ColorShadingCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
void ColorPickerToggleButton_Clicked(object sender, RoutedEventArgs e)
{
if (_currentColorPosition != null)
{
Point _newPoint = new Point
{
X = ((Point)_currentColorPosition).X * e.NewSize.Width,
Y = ((Point)_currentColorPosition).Y * e.NewSize.Height
};
UpdateColorShadeSelectorPositionAndCalculateColor(_newPoint, false);
}
_colorPickerCanvasPopup.IsOpen = _colorPickerToggleButton.IsChecked ?? false;
}
void SpectrumSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
private void Color_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_currentColorPosition != null)
{
CalculateColor((Point)_currentColorPosition);
}
}
ListBox lb = (ListBox)sender;
void OkButton_Click(object sender, RoutedEventArgs e)
{
if (_colorPickerCanvasPopup.IsOpen || _colorPickerToggleButton.IsChecked == true)
if (e.AddedItems.Count > 0)
{
var colorItem = (ColorItem)e.AddedItems[0];
SelectedColor = colorItem.Color;
UpdateRecentColors(colorItem);
CloseColorPicker();
SelectedColor = CurrentColor;
lb.SelectedIndex = -1; //for now I don't care about keeping track of the selected color
}
}
void ColorPickerToggleButton_Clicked(object sender, RoutedEventArgs e)
{
_colorPickerCanvasPopup.IsOpen = _colorPickerToggleButton.IsChecked ?? false;
}
#endregion //Event Handlers
#region Methods
@ -328,67 +148,48 @@ namespace Microsoft.Windows.Controls
_colorPickerCanvasPopup.IsOpen = false;
}
private void SetSelectedColor(Color theColor)
private void UpdateRecentColors(ColorItem colorItem)
{
_currentColor = theColor;
SetValue(AProperty, _currentColor.A);
SetValue(RProperty, _currentColor.R);
SetValue(GProperty, _currentColor.G);
SetValue(BProperty, _currentColor.B);
UpdateColorShadeSelectorPosition(_currentColor);
if (!RecentColors.Contains(colorItem))
RecentColors.Add(colorItem);
if (RecentColors.Count > 10) //don't allow more than ten, maybe make a property that can be set by the user.
RecentColors.RemoveAt(0);
}
private void UpdateColorShadeSelectorPositionAndCalculateColor(Point p, bool calculateColor)
private static ObservableCollection<ColorItem> CreateStandardColors()
{
if (p.Y < 0)
p.Y = 0;
if (p.X < 0)
p.X = 0;
if (p.X > _colorShadingCanvas.ActualWidth)
p.X = _colorShadingCanvas.ActualWidth;
if (p.Y > _colorShadingCanvas.ActualHeight)
p.Y = _colorShadingCanvas.ActualHeight;
_colorShadeSelectorTransform.X = p.X - (_colorShadeSelector.Width / 2);
_colorShadeSelectorTransform.Y = p.Y - (_colorShadeSelector.Height / 2);
p.X = p.X / _colorShadingCanvas.ActualWidth;
p.Y = p.Y / _colorShadingCanvas.ActualHeight;
_currentColorPosition = p;
if (calculateColor)
CalculateColor(p);
ObservableCollection<ColorItem> _standardColors = new ObservableCollection<ColorItem>();
_standardColors.Add(new ColorItem(Colors.White, "White"));
_standardColors.Add(new ColorItem(Colors.Gray, "Gray"));
_standardColors.Add(new ColorItem(Colors.Black, "Black"));
_standardColors.Add(new ColorItem(Colors.Red, "Red"));
_standardColors.Add(new ColorItem(Colors.Green, "Geen"));
_standardColors.Add(new ColorItem(Colors.Blue, "Blue"));
_standardColors.Add(new ColorItem(Colors.Yellow, "Yellow"));
_standardColors.Add(new ColorItem(Colors.Orange, "Orange"));
_standardColors.Add(new ColorItem(Colors.Brown, "Brown"));
_standardColors.Add(new ColorItem(Colors.Purple, "Purple"));
return _standardColors;
}
private void UpdateColorShadeSelectorPosition(Color color)
private static ObservableCollection<ColorItem> CreateAvailableColors()
{
if (_spectrumSlider == null || _colorShadingCanvas == null)
return;
_currentColorPosition = null;
ObservableCollection<ColorItem> _standardColors = new ObservableCollection<ColorItem>();
HsvColor hsv = ColorUtilities.ConvertRgbToHsv(color.R, color.G, color.B);
_spectrumSlider.Value = hsv.H;
Point p = new Point(hsv.S, 1 - hsv.V);
_currentColorPosition = p;
_colorShadeSelectorTransform.X = (p.X * _colorShadingCanvas.Width) - 5;
_colorShadeSelectorTransform.Y = (p.Y * _colorShadingCanvas.Height) - 5;
}
PropertyInfo[] properties = typeof(Colors).GetProperties(BindingFlags.Static | BindingFlags.Public);
foreach (PropertyInfo info in properties)
{
if (String.Compare(info.Name, "Transparent", false) != 0)
{
Color c = (Color)info.GetValue(typeof(Colors), null);
var colorItem = new ColorItem(c, info.Name);
if (!_standardColors.Contains(colorItem))
_standardColors.Add(colorItem);
}
}
private void CalculateColor(Point p)
{
HsvColor hsv = new HsvColor(360 - _spectrumSlider.Value, 1, 1) { S = p.X, V = 1 - p.Y };
_currentColor = ColorUtilities.ConvertHsvToRgb(hsv.H, hsv.S, hsv.V); ;
_currentColor.ScA = ScA;
CurrentColor = _currentColor;
HexadecimalString = _currentColor.ToString();
return _standardColors;
}
#endregion //Methods

85
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorSpectrumSlider.cs

@ -1,85 +0,0 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Microsoft.Windows.Controls
{
internal class ColorSpectrumSlider : Slider
{
#region Private Members
private Rectangle _spectrumDisplay;
private LinearGradientBrush _pickerBrush;
#endregion //Private Members
#region Constructors
static ColorSpectrumSlider()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorSpectrumSlider), new FrameworkPropertyMetadata(typeof(ColorSpectrumSlider)));
}
#endregion //Constructors
#region Dependency Properties
public static readonly DependencyProperty SelectedColorProperty = DependencyProperty.Register("SelectedColor", typeof(Color), typeof(ColorSpectrumSlider), new PropertyMetadata(System.Windows.Media.Colors.Transparent));
public Color SelectedColor
{
get { return (Color)GetValue(SelectedColorProperty); }
set { SetValue(SelectedColorProperty, value); }
}
#endregion //Dependency Properties
#region Base Class Overrides
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_spectrumDisplay = (Rectangle)GetTemplateChild("PART_SpectrumDisplay");
CreateSpectrum();
OnValueChanged(Double.NaN, Value);
}
protected override void OnValueChanged(double oldValue, double newValue)
{
base.OnValueChanged(oldValue, newValue);
Color color = ColorUtilities.ConvertHsvToRgb(360 - newValue, 1, 1);
SelectedColor = color;
}
#endregion //Base Class Overrides
#region Methods
private void CreateSpectrum()
{
_pickerBrush = new LinearGradientBrush();
_pickerBrush.StartPoint = new Point(0.5, 0);
_pickerBrush.EndPoint = new Point(0.5, 1);
_pickerBrush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation;
List<Color> colorsList = ColorUtilities.GenerateHsvSpectrum();
double stopIncrement = (double)1 / colorsList.Count;
int i;
for (i = 0; i < colorsList.Count; i++)
{
_pickerBrush.GradientStops.Add(new GradientStop(colorsList[i], i * stopIncrement));
}
_pickerBrush.GradientStops[i - 1].Offset = 1.0;
_spectrumDisplay.Fill = _pickerBrush;
}
#endregion //Methods
}
}

156
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/ColorUtilities.cs

@ -1,156 +0,0 @@
using System;
using System.Collections.Generic;
using System.Windows.Media;
namespace Microsoft.Windows.Controls
{
internal static class ColorUtilities
{
/// <summary>
/// Converts an RGB color to an HSV color.
/// </summary>
/// <param name="r"></param>
/// <param name="b"></param>
/// <param name="g"></param>
/// <returns></returns>
public static HsvColor ConvertRgbToHsv(int r, int b, int g)
{
double delta, min;
double h = 0, s, v;
min = Math.Min(Math.Min(r, g), b);
v = Math.Max(Math.Max(r, g), b);
delta = v - min;
if (v == 0.0)
{
s = 0;
}
else
s = delta / v;
if (s == 0)
h = 0.0;
else
{
if (r == v)
h = (g - b) / delta;
else if (g == v)
h = 2 + (b - r) / delta;
else if (b == v)
h = 4 + (r - g) / delta;
h *= 60;
if (h < 0.0)
h = h + 360;
}
return new HsvColor { H = h, S = s, V = v / 255 };
}
/// <summary>
/// Converts an HSV color to an RGB color.
/// </summary>
/// <param name="h"></param>
/// <param name="s"></param>
/// <param name="v"></param>
/// <returns></returns>
public static Color ConvertHsvToRgb(double h, double s, double v)
{
double r = 0, g = 0, b = 0;
if (s == 0)
{
r = v;
g = v;
b = v;
}
else
{
int i;
double f, p, q, t;
if (h == 360)
h = 0;
else
h = h / 60;
i = (int)Math.Truncate(h);
f = h - i;
p = v * (1.0 - s);
q = v * (1.0 - (s * f));
t = v * (1.0 - (s * (1.0 - f)));
switch (i)
{
case 0:
{
r = v;
g = t;
b = p;
break;
}
case 1:
{
r = q;
g = v;
b = p;
break;
}
case 2:
{
r = p;
g = v;
b = t;
break;
}
case 3:
{
r = p;
g = q;
b = v;
break;
}
case 4:
{
r = t;
g = p;
b = v;
break;
}
default:
{
r = v;
g = p;
b = q;
break;
}
}
}
return Color.FromArgb(255, (byte)(r * 255), (byte)(g * 255), (byte)(b * 255));
}
/// <summary>
/// Generates a list of colors with hues ranging from 0 360 and a saturation and value of 1.
/// </summary>
/// <returns></returns>
public static List<Color> GenerateHsvSpectrum()
{
List<Color> colorsList = new List<Color>(8);
for (int i = 0; i < 29; i++)
{
colorsList.Add(ColorUtilities.ConvertHsvToRgb(i * 12, 1, 1));
}
colorsList.Add(ColorUtilities.ConvertHsvToRgb(0, 1, 1));
return colorsList;
}
}
}

18
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/ColorPicker/HsvColor.cs

@ -1,18 +0,0 @@
using System;
namespace Microsoft.Windows.Controls
{
internal struct HsvColor
{
public double H;
public double S;
public double V;
public HsvColor(double h, double s, double v)
{
H = h;
S = s;
V = v;
}
}
}

364
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Themes/Generic.xaml

@ -582,127 +582,6 @@
<GradientStop Color="#FF617584" Offset="1"/>
</LinearGradientBrush>
<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>
<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="VerticalSlideThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Canvas x:Name="selector" Height="8" Background="Transparent" IsHitTestVisible="True" >
<Path Width="5" Height="8" 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 " />
<Path Width="5" Height="8" Canvas.Top="8" Canvas.Left="20" 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 ">
<Path.RenderTransform>
<RotateTransform Angle="180"/>
</Path.RenderTransform>
</Path>
</Canvas>
<ControlTemplate.Triggers>
<Trigger Property="IsDragging" Value="True">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="OpacitySliderStyle" TargetType="{x:Type Slider}">
<Setter Property="Orientation" Value="Vertical"/>
<Setter Property="Minimum" Value="0" />
<Setter Property="Maximum" Value="1" />
<Setter Property="TickFrequency" Value="0.01" />
<Setter Property="SmallChange" Value="0.01" />
<Setter Property="LargeChange" Value="0.02" />
<Setter Property="IsDirectionReversed" Value="False" />
<Setter Property="IsMoveToPointEnabled" Value="True" />
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterY="0.5" CenterX="0.5"/>
<SkewTransform CenterY="0.5" CenterX="0.5"/>
<RotateTransform Angle="90" CenterY="0.5" CenterX="0.5"/>
<TranslateTransform/>
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="White" />
<GradientStop Color="Transparent" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Slider}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border x:Name="PART_TrackBackground" Background="{TemplateBinding Background}" Grid.Column="1" Width="20" />
<Track Grid.Column="1" 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="ColorPickerToggleButton" TargetType="ToggleButton">
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="Padding" Value="5"/>
@ -768,117 +647,146 @@
</Setter>
</Style>
<LinearGradientBrush x:Key="PopupBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Offset="0" Color="#FFffffff"/>
<GradientStop Offset="1" Color="#FFE8EBED"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
<Style x:Key="ColorPaletteLisBoxStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="ToolTip" Value="{Binding Name}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid ToolTip="{Binding Name}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
<Border BorderThickness="1" Background="Transparent" BorderBrush="Transparent" x:Name="_outerBorder" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Border Background="Transparent" BorderThickness="1" BorderBrush="Transparent" x:Name="_innerBorder" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="_outerBorder" Property="BorderBrush" Value="#FFFF0000" />
<Setter TargetName="_innerBorder" Property="BorderBrush" Value="#FFFFFF00" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="_outerBorder" Property="BorderBrush" Value="#FFFF0000" />
<Setter TargetName="_innerBorder" Property="BorderBrush" Value="#FFFFFF00" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate x:Key="ColorItemTemplate">
<Grid>
<Border BorderBrush="#FFC9CACA" BorderThickness="1" Margin="2,2,2,2" >
<Rectangle Width="14" Height="14">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Color}" />
</Rectangle.Fill>
</Rectangle>
</Border>
</Grid>
</DataTemplate>
<Style TargetType="{x:Type local:ColorPicker}">
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ColorPicker}">
<Grid>
<Border BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" BorderThickness="1" CornerRadius="1">
<Border BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" BorderThickness="1" CornerRadius="0">
<Grid>
<ToggleButton x:Name="PART_ColorPickerToggleButton" Style="{StaticResource ColorPickerToggleButton}" Height="25">
<ToggleButton x:Name="PART_ColorPickerToggleButton" Style="{StaticResource ColorPickerToggleButton}" MinHeight="22">
<ToggleButton.Background>
<SolidColorBrush Color="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}}"/>
</ToggleButton.Background>
<ToggleButton.Content>
<Grid x:Name="arrowGlyph" IsHitTestVisible="False">
<Path Height="3" Width="5" Stretch="Fill" Fill="#FFFFFFFF" Margin="0,1,0,0"
Data="M 0,0 C0,0 0,1 0,1 0,1 1,1 1,1 1,1 1,2 1,2 1,2 2,2 2,2 2,2 2,3 2,3 2,3 3,3 3,3 3,3 3,2 3,2 3,2 4,2 4,2 4,2 4,1 4,1 4,1 5,1 5,1 5,1 5,0 5,0 5,0 0,0 0,0 z" />
<Path Height="3" Width="5" Stretch="Fill" Fill="{StaticResource ColorPickerDarkBorderBrush}"
Data="M 0,0 C0,0 0,1 0,1 0,1 1,1 1,1 1,1 1,2 1,2 1,2 2,2 2,2 2,2 2,3 2,3 2,3 3,3 3,3 3,3 3,2 3,2 3,2 4,2 4,2 4,2 4,1 4,1 4,1 5,1 5,1 5,1 5,0 5,0 5,0 0,0 0,0 z" />
<Path Width="7" Height="4" Data="M 0,1 C0,1 0,0 0,0 0,0 3,0 3,0 3,0 3,1 3,1 3,1 4,1 4,1 4,1 4,0 4,0 4,0 7,0 7,0 7,0 7,1 7,1 7,1 6,1 6,1 6,1 6,2 6,2 6,2 5,2 5,2 5,2 5,3 5,3 5,3 4,3 4,3 4,3 4,4 4,4 4,4 3,4 3,4 3,4 3,3 3,3 3,3 2,3 2,3 2,3 2,2 2,2 2,2 1,2 1,2 1,2 1,1 1,1 1,1 0,1 0,1 z" Fill="#FF000000"/>
</Grid>
</ToggleButton.Content>
</ToggleButton>
</Grid>
</Border>
<Popup x:Name="PART_ColorPickerCanvasPopup" VerticalAlignment="Bottom" IsOpen="False" >
<Border BorderThickness="1" Background="White" BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" Padding="3">
<Grid>
<Popup x:Name="PART_ColorPickerPalettePopup" VerticalAlignment="Bottom" IsOpen="False" >
<Border BorderThickness="1" Background="{StaticResource PopupBackgroundBrush}" BorderBrush="{StaticResource ColorPickerDarkBorderBrush}" Padding="3">
<Grid Margin="4">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Margin="2">
<!-- Available Colors -->
<Grid Grid.Row="1">
<Grid>
<Grid.ColumnDefinitions >
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="5"></ColumnDefinition>
<ColumnDefinition Width="22"></ColumnDefinition>
<ColumnDefinition Width="5"></ColumnDefinition>
<ColumnDefinition Width="22"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="20"/>
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="Available Colors" Background="AliceBlue" Padding="2" Margin="0,0,0,1" />
<ListBox x:Name="PART_AvailableColors" Grid.Row="1" Background="Transparent" BorderThickness="0" SelectionMode="Single"
ItemsSource="{Binding AvailableColors, RelativeSource={RelativeSource TemplatedParent}}"
ItemTemplate="{StaticResource ColorItemTemplate}"
ItemContainerStyle="{StaticResource ColorPaletteLisBoxStyle}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="200" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Grid>
<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}" >
<Rectangle.Fill>
<SolidColorBrush Color="{Binding ElementName=PART_SpectrumSlider, Path=SelectedColor}" />
</Rectangle.Fill>
</Rectangle>
<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 BorderThickness="0,1,0,0" Grid.Row="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Background="{StaticResource CheckerBrush}">
<Rectangle x:Name="SelectedColor">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}}"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
<Grid Grid.Column="1" Background="{StaticResource CheckerBrush}">
<Rectangle x:Name="CurrentColor">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding CurrentColor, RelativeSource={RelativeSource TemplatedParent}}"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</Grid>
</Border>
<Border BorderThickness="1" BorderBrush="DarkGray" Grid.Column="2" Grid.RowSpan="2" ClipToBounds="True">
<local:ColorSpectrumSlider x:Name="PART_SpectrumSlider" Width="20" />
</Border>
<Border Grid.Column="4" Grid.RowSpan="2" BorderThickness="1" BorderBrush="DarkGray" Background="{StaticResource CheckerBrush}" ClipToBounds="True">
<Slider x:Name="PART_OpacitySlider"
Style="{StaticResource OpacitySliderStyle}"
Value="{Binding Path=ScA, RelativeSource={RelativeSource TemplatedParent}}"/>
</Border>
<!-- Standard Colors-->
<Grid Grid.Row="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="Standard Colors" Background="AliceBlue" Padding="2" Margin="0,1,0,1"/>
<ListBox x:Name="PART_StandardColors" Grid.Row="1" SelectionMode="Single" Background="Transparent" BorderThickness="0"
ItemsSource="{Binding StandardColors, RelativeSource={RelativeSource TemplatedParent}}"
ItemTemplate="{StaticResource ColorItemTemplate}"
ItemContainerStyle="{StaticResource ColorPaletteLisBoxStyle}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="200" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Grid>
<Button x:Name="PART_OkButton" Grid.Row="1" HorizontalAlignment="Right" MinWidth="50" Cursor="Hand" Content="OK" />
<!-- Recent Colors-->
<Grid Grid.Row="3" Margin="0,1,0,1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="Recent Colors" Background="AliceBlue" Padding="2" Margin="0,1,0,1"/>
<ListBox x:Name="PART_RecentColors" Grid.Row="1" SelectionMode="Single" Background="Transparent" BorderThickness="0"
ItemsSource="{Binding RecentColors, RelativeSource={RelativeSource TemplatedParent}}"
ItemTemplate="{StaticResource ColorItemTemplate}"
ItemContainerStyle="{StaticResource ColorPaletteLisBoxStyle}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Width="200" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Grid>
</Grid>
</Border>
</Popup>
@ -888,52 +796,6 @@
</Setter>
</Style>
<Style TargetType="{x:Type local:ColorSpectrumSlider}">
<Setter Property="Orientation" Value="Vertical"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Minimum" Value="1"/>
<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="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ColorSpectrumSlider}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border x:Name="PART_TrackBackground" Grid.Column="1" Width="20">
<Rectangle x:Name="PART_SpectrumDisplay" Stretch="Fill" VerticalAlignment="Stretch" />
</Border>
<Track Grid.Column="1" 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>
<!-- =============================================================================== -->
<!-- ButtonSpinner -->
<!-- =============================================================================== -->

6
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -68,14 +68,12 @@
<Compile Include="ChildWindow\ChildWindow.cs" />
<Compile Include="ChildWindow\VisualStates.ChildWindow.cs" />
<Compile Include="ChildWindow\WindowState.cs" />
<Compile Include="ColorPicker\ColorPicker.cs" />
<Compile Include="ColorPicker\HsvColor.cs" />
<Compile Include="ColorPicker\ColorUtilities.cs" />
<Compile Include="ColorPicker\ColorSpectrumSlider.cs" />
<Compile Include="ButtonSpinner\SpinDirection.cs" />
<Compile Include="ButtonSpinner\SpinEventArgs.cs" />
<Compile Include="ButtonSpinner\Spinner.cs" />
<Compile Include="ButtonSpinner\ValidSpinDirections.cs" />
<Compile Include="ColorPicker\ColorItem.cs" />
<Compile Include="ColorPicker\ColorPicker.cs" />
<Compile Include="Core\Converters\InverseBoolConverter.cs" />
<Compile Include="DateTimeUpDown\DateTimeFormat.cs" />
<Compile Include="DateTimeUpDown\DateTimeInfo.cs" />

Loading…
Cancel
Save