diff --git a/src/ColorPickerWPF/ColorPickRow.xaml.cs b/src/ColorPickerWPF/ColorPickRow.xaml.cs index d20c81c..d933480 100644 --- a/src/ColorPickerWPF/ColorPickRow.xaml.cs +++ b/src/ColorPickerWPF/ColorPickRow.xaml.cs @@ -25,7 +25,12 @@ public ColorPickRow() private void PickColorButton_OnClick(object sender, RoutedEventArgs e) { Color color; - if (ColorPickerWindow.ShowDialog(out color, Options)) + Color? initialColor = null; + if(ColorDisplayGrid.Background is SolidColorBrush scb) + { + initialColor = scb.Color; + } + if (ColorPickerWindow.ShowDialog(out color, Options, initialColor:initialColor)) { SetColor(color); OnPick?.Invoke(this, EventArgs.Empty); diff --git a/src/ColorPickerWPF/ColorPickerControl.xaml b/src/ColorPickerWPF/ColorPickerControl.xaml index d8cc79c..e9dab0a 100644 --- a/src/ColorPickerWPF/ColorPickerControl.xaml +++ b/src/ColorPickerWPF/ColorPickerControl.xaml @@ -27,7 +27,7 @@ MouseDown="SampleImage_OnMouseDown"/> - + 0 && pos.Y > 0 && pos.X < img.PixelWidth && pos.Y < img.PixelHeight) + SampleImageClick(img, pos); + } + private void ColorPickerControl_MouseUp(object sender, MouseButtonEventArgs e) { Mouse.Capture(null); this.MouseMove -= ColorPickerControl_MouseMove; this.MouseUp -= ColorPickerControl_MouseUp; } - - private void SampleImage2_OnMouseDown(object sender, MouseButtonEventArgs e) + private void ColorPickerControl2_MouseUp(object sender, MouseButtonEventArgs e) { - var pos = e.GetPosition(SampleImage2); - var img = SampleImage2.Source as BitmapSource; - SampleImageClick(img, pos); + Mouse.Capture(null); + this.MouseMove -= ColorPickerControl2_MouseMove; + this.MouseUp -= ColorPickerControl2_MouseUp; } private void Swatch_OnOnPickColor(Color color) @@ -339,6 +355,11 @@ private void UpdateImageForHSV() SampleImage2.Source = writableImage; } + private void OnPicker2Selected(object sender, RoutedEventArgs e) + { + PickerHueSlider.Value = Color.GetHue(); + } + private void LSlider_OnOnValueChanged(double value) { if (!IsSettingValues) diff --git a/src/ColorPickerWPF/ColorPickerWindow.xaml.cs b/src/ColorPickerWPF/ColorPickerWindow.xaml.cs index f7f4c58..7ff8b1c 100644 --- a/src/ColorPickerWPF/ColorPickerWindow.xaml.cs +++ b/src/ColorPickerWPF/ColorPickerWindow.xaml.cs @@ -20,7 +20,7 @@ public ColorPickerWindow() InitializeComponent(); } - public static bool ShowDialog(out Color color, ColorPickerDialogOptions flags = ColorPickerDialogOptions.None, ColorPickerControl.ColorPickerChangeHandler customPreviewEventHandler = null) + public static bool ShowDialog(out Color color, ColorPickerDialogOptions flags = ColorPickerDialogOptions.None, ColorPickerControl.ColorPickerChangeHandler customPreviewEventHandler = null, Color? initialColor=null) { if ((flags & ColorPickerDialogOptions.LoadCustomPalette) == ColorPickerDialogOptions.LoadCustomPalette) { @@ -28,6 +28,10 @@ public static bool ShowDialog(out Color color, ColorPickerDialogOptions flags = } var instance = new ColorPickerWindow(); + if(initialColor.HasValue) + { + instance.ColorPicker.SetColor(initialColor.Value); + } color = instance.ColorPicker.Color; if ((flags & ColorPickerDialogOptions.SimpleView) == ColorPickerDialogOptions.SimpleView)