/// <summary> /// Updates the Color property any time the text changes /// </summary> protected override void OnTextChanged(System.Windows.Controls.TextChangedEventArgs e) { base.OnTextChanged(e); ColorSetInternally = true; Color = ColorPickerUtil.ColorFromString(this.Text); ColorBrush = new SolidColorBrush(Color); ColorSetInternally = false; }
/// <summary> /// Shared property changed callback to update the Color property /// </summary> public static void UpdateColorHSB(object o, DependencyPropertyChangedEventArgs e) { ColorPicker c = (ColorPicker)o; Color n = ColorPickerUtil.ColorFromAHSB(c.Alpha, c.Hue, c.Saturation, c.Brightness); c.HSBSetInternally = true; c.Color = n; c.ColorBrush = new SolidColorBrush(n); c.HSBSetInternally = false; }
public static void OnColorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { ColorPicker c = (ColorPicker)o; if (e.NewValue is Color) { Color color = (Color)e.NewValue; if (!c.HSBSetInternally) { // update HSB value based on new value of color double H = 0; double S = 0; double B = 0; ColorPickerUtil.HSBFromColor(color, ref H, ref S, ref B); c.HSBSetInternally = true; c.Alpha = (double)(color.A / 255); c.Hue = H; c.Saturation = S; c.Brightness = B; c.HSBSetInternally = false; } if (!c.RGBSetInternally) { // update RGB value based on new value of color c.RGBSetInternally = true; c.A = color.A; c.R = color.R; c.G = color.G; c.B = color.B; c.RGBSetInternally = false; } c.RaiseColorChangedEvent((Color)e.NewValue); } }
protected override void OnRender(DrawingContext dc) { LinearGradientBrush h = new LinearGradientBrush(); h.StartPoint = new Point(0, 0); h.EndPoint = new Point(1, 0); h.GradientStops.Add(new GradientStop(Colors.White, 0.00)); h.GradientStops.Add(new GradientStop(ColorPickerUtil.ColorFromHSB(Hue, 1, 1), 1.0)); dc.DrawRectangle(h, null, new Rect(0, 0, ActualWidth, ActualHeight)); LinearGradientBrush v = new LinearGradientBrush(); v.StartPoint = new Point(0, 0); v.EndPoint = new Point(0, 1); v.GradientStops.Add(new GradientStop(Color.FromArgb(0xFF, 0, 0, 0), 1.00)); v.GradientStops.Add(new GradientStop(Color.FromArgb(0x80, 0, 0, 0), 0.50)); v.GradientStops.Add(new GradientStop(Color.FromArgb(0x00, 0, 0, 0), 0.00)); dc.DrawRectangle(v, null, new Rect(0, 0, ActualWidth, ActualHeight)); UpdateSaturationOffset(); UpdateBrightnessOffset(); }
public void UpdateColor() { Color = ColorPickerUtil.ColorFromHSB(Hue, Saturation, Brightness); ColorBrush = new SolidColorBrush(Color); }
private void UpdateColor() { Color = ColorPickerUtil.ColorFromHSB(Hue, 1, 1); ColorBrush = new SolidColorBrush(Color); }