diff --git a/src/Shared/HandyControl_Shared/Controls/ColorPicker/ColorPicker.cs b/src/Shared/HandyControl_Shared/Controls/ColorPicker/ColorPicker.cs index f8348369..30974f1b 100644 --- a/src/Shared/HandyControl_Shared/Controls/ColorPicker/ColorPicker.cs +++ b/src/Shared/HandyControl_Shared/Controls/ColorPicker/ColorPicker.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows; @@ -178,20 +178,30 @@ namespace HandyControl.Controls #region Public Events + public static readonly RoutedEvent SelectedColorChangedEvent = + EventManager.RegisterRoutedEvent("SelectedColorChanged", RoutingStrategy.Bubble, + typeof(EventHandler>), typeof(ColorPicker)); + + public event EventHandler> SelectedColorChanged + { + add => AddHandler(SelectedColorChangedEvent, value); + remove => RemoveHandler(SelectedColorChangedEvent, value); + } + /// /// 颜色改变事件 /// - public static readonly RoutedEvent SelectedColorChangedEvent = - EventManager.RegisterRoutedEvent("SelectedColorChanged", RoutingStrategy.Bubble, + public static readonly RoutedEvent ConfirmedEvent = + EventManager.RegisterRoutedEvent("Confirmed", RoutingStrategy.Bubble, typeof(EventHandler>), typeof(ColorPicker)); /// /// 颜色改变事件 /// - public event EventHandler> SelectedColorChanged + public event EventHandler> Confirmed { - add => AddHandler(SelectedColorChangedEvent, value); - remove => RemoveHandler(SelectedColorChangedEvent, value); + add => AddHandler(ConfirmedEvent, value); + remove => RemoveHandler(ConfirmedEvent, value); } /// @@ -268,6 +278,10 @@ namespace HandyControl.Controls } ctl.UpdateStatus(v.Color); ctl.SelectedBrushWithoutOpacity = new SolidColorBrush(Color.FromRgb(v.Color.R, v.Color.G, v.Color.B)); + ctl.RaiseEvent(new FunctionEventArgs(SelectedColorChangedEvent, ctl) + { + Info = v.Color + }); })); /// @@ -361,6 +375,8 @@ namespace HandyControl.Controls _isLoaded = true; } }; + + cPicker = this; } public override void OnApplyTemplate() @@ -695,10 +711,14 @@ namespace HandyControl.Controls } private void ButtonConfirm_OnClick(object sender, RoutedEventArgs e) - => RaiseEvent(new FunctionEventArgs(SelectedColorChangedEvent, this) - { - Info = SelectedBrush.Color - }); + { + RaiseEvent(new FunctionEventArgs(ConfirmedEvent, this) + { + Info = SelectedBrush.Color + }); + + RaiseEvent(new RoutedEventArgs(CanceledEvent)); + } private void ButtonCancel_OnClick(object sender, RoutedEventArgs e) => RaiseEvent(new RoutedEventArgs(CanceledEvent)); @@ -731,6 +751,5 @@ namespace HandyControl.Controls } public bool CanDispose { get; } = true; - } }