Skip to content

Commit 2bf587c

Browse files
committed
Minor
1 parent 3f800c7 commit 2bf587c

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

JL.Windows/Utilities/WindowsUtils.cs

+25-11
Original file line numberDiff line numberDiff line change
@@ -489,31 +489,45 @@ public static Size MeasureTextSize(string text, double fontSize)
489489

490490
public static void ShowColorPicker(Button button)
491491
{
492-
using ColorPicker picker = SingleOpenHelper.CreateControl<ColorPicker>();
492+
ColorPicker picker = SingleOpenHelper.CreateControl<ColorPicker>();
493493
HandyControl.Controls.PopupWindow window = new()
494494
{
495495
PopupElement = picker,
496496
WindowStartupLocation = WindowStartupLocation.CenterScreen
497497
};
498+
498499
picker.SelectedBrush = (SolidColorBrush)button.Tag;
500+
picker.Tag = (window, button);
501+
picker.Canceled += ColorPicker_Cancelled;
502+
picker.Confirmed += ColorPicker_Confirmed;
499503

500-
picker.Canceled += delegate
501-
{
502-
window.Close();
503-
};
504+
window.ShowDialog(picker, false);
505+
}
504506

505-
picker.Confirmed += delegate
507+
private static void ColorPicker_Cancelled(object? sender, EventArgs e)
508+
{
509+
if (sender is not ColorPicker colorPicker)
506510
{
507-
ConfirmColor(button, picker.SelectedBrush, window);
508-
};
511+
return;
512+
}
509513

510-
window.ShowDialog(picker, false);
514+
(HandyControl.Controls.PopupWindow window, _) = ((HandyControl.Controls.PopupWindow, Button))colorPicker.Tag;
515+
516+
window.Close();
517+
colorPicker.Dispose();
511518
}
512519

513-
private static void ConfirmColor(Button button, Brush selectedBrush, Window window)
520+
private static void ColorPicker_Confirmed(object? sender, FunctionEventArgs<Color> e)
514521
{
515-
SetButtonColor(button, selectedBrush);
522+
if (sender is not ColorPicker colorPicker)
523+
{
524+
return;
525+
}
526+
527+
(HandyControl.Controls.PopupWindow window, Button button) = ((HandyControl.Controls.PopupWindow, Button))colorPicker.Tag;
528+
SetButtonColor(button, colorPicker.SelectedBrush);
516529
window.Close();
530+
colorPicker.Dispose();
517531
}
518532

519533
public static void SetButtonColor(Button button, Brush selectedBrush)

0 commit comments

Comments
 (0)