From 0baae519cbee13c1bb3dd2c52329a6cb2ddd9746 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 23 Oct 2018 10:35:31 +0800 Subject: [PATCH] 1. add stepchanged event to stepbar 2. simplify the logic of close callback of growl 3. Make sure that the path is displayed properly when flowdirection is rtl --- HandyControl/Controls/Growl.cs | 26 ++++++++++++++----- HandyControl/Controls/Steps/StepBar.cs | 25 ++++++++++++++++++ HandyControl/Properties/AssemblyInfo.cs | 3 +-- HandyControl/Themes/Basic/Paths.xaml | 3 +++ .../ViewModel/GrowlDemoViewModel.cs | 6 ++--- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/HandyControl/Controls/Growl.cs b/HandyControl/Controls/Growl.cs index 552f2b92..abe86a29 100644 --- a/HandyControl/Controls/Growl.cs +++ b/HandyControl/Controls/Growl.cs @@ -105,7 +105,7 @@ namespace HandyControl.Controls /// private DispatcherTimer _timerClose; - private Action CloseAction { get; set; } + private Func ActionBeforeClose { get; set; } public string Message { @@ -191,7 +191,7 @@ namespace HandyControl.Controls private void Update() { - if (CloseAction != null) + if (ActionBeforeClose != null) { _staysOpen = true; _showCloseButton = false; @@ -211,7 +211,7 @@ namespace HandyControl.Controls /// /// 显示信息 /// - private static void Show(string message, string iconKey, string iconBrushKey, Action closeAction = null, + private static void Show(string message, string iconKey, string iconBrushKey, Func actionBeforeClose = null, bool staysOpen = false, bool showCloseButton = true) { var ctl = new Growl @@ -221,7 +221,7 @@ namespace HandyControl.Controls Icon = ResourceHelper.GetResource(iconKey), IconBrush = ResourceHelper.GetResource(iconBrushKey), _showCloseButton = showCloseButton, - CloseAction = closeAction, + ActionBeforeClose = actionBeforeClose, _staysOpen = staysOpen }; GrowlPanel.Children.Insert(0, ctl); @@ -261,7 +261,7 @@ namespace HandyControl.Controls Show(message, "FatalGeometry", "PrimaryTextBrush", null, true, false); } - public static void Ask(string message, Action closeAction) => Show(message, "AskGeometry", "AccentBrush", closeAction); + public static void Ask(string message, Func actionBeforeClose) => Show(message, "AskGeometry", "AccentBrush", actionBeforeClose); private void ButtonClose_OnClick(object sender, RoutedEventArgs e) => Close(); @@ -287,8 +287,20 @@ namespace HandyControl.Controls GrowlPanel.Show(); } - private void ButtonCancel_OnClick(object sender, RoutedEventArgs e) => CloseAction?.Invoke(Close, false); + private void ButtonCancel_OnClick(object sender, RoutedEventArgs e) + { + if (ActionBeforeClose?.Invoke(false) == true) + { + Close(); + } + } - private void ButtonOk_OnClick(object sender, RoutedEventArgs e) => CloseAction?.Invoke(Close, true); + private void ButtonOk_OnClick(object sender, RoutedEventArgs e) + { + if (ActionBeforeClose?.Invoke(true) == true) + { + Close(); + } + } } } \ No newline at end of file diff --git a/HandyControl/Controls/Steps/StepBar.cs b/HandyControl/Controls/Steps/StepBar.cs index 45506a98..57696860 100644 --- a/HandyControl/Controls/Steps/StepBar.cs +++ b/HandyControl/Controls/Steps/StepBar.cs @@ -7,6 +7,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; +using HandyControl.Data; using HandyControl.Interactivity; using HandyControl.Tools; @@ -34,6 +35,22 @@ namespace HandyControl.Controls #endregion Constants + /// + /// 步骤改变事件 + /// + public static readonly RoutedEvent StepChangedEvent = + EventManager.RegisterRoutedEvent("StepChanged", RoutingStrategy.Bubble, + typeof(EventHandler>), typeof(StepBar)); + + /// + /// 步骤改变事件 + /// + public event EventHandler> StepChanged + { + add => AddHandler(StepChangedEvent, value); + remove => RemoveHandler(StepChangedEvent, value); + } + public StepBar() { Loaded += (s1, e1) => @@ -106,6 +123,10 @@ namespace HandyControl.Controls StepIndex = _panelMain.Children.Count - 1; return; } + RaiseEvent(new FunctionEventArgs(StepChangedEvent, this) + { + Info = StepIndex + }); if (_panelMain.Children[StepIndex - 1] is StepItem stepItemFinished) stepItemFinished.Status = true; if (_panelMain.Children[StepIndex] is StepItem stepItemSelected) @@ -121,6 +142,10 @@ namespace HandyControl.Controls StepIndex = 0; return; } + RaiseEvent(new FunctionEventArgs(StepChangedEvent, this) + { + Info = StepIndex + }); if (_panelMain.Children[StepIndex + 1] is StepItem stepItemFinished) stepItemFinished.Status = null; if (_panelMain.Children[StepIndex] is StepItem stepItemSelected) diff --git a/HandyControl/Properties/AssemblyInfo.cs b/HandyControl/Properties/AssemblyInfo.cs index c125362e..f0bf5245 100644 --- a/HandyControl/Properties/AssemblyInfo.cs +++ b/HandyControl/Properties/AssemblyInfo.cs @@ -10,5 +10,4 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] -[assembly: AssemblyVersion("1.3.4")] -[assembly: AssemblyFileVersion("1.3.4")] +[assembly: AssemblyVersion("1.3.4.*")] diff --git a/HandyControl/Themes/Basic/Paths.xaml b/HandyControl/Themes/Basic/Paths.xaml index 8613e529..ece30805 100644 --- a/HandyControl/Themes/Basic/Paths.xaml +++ b/HandyControl/Themes/Basic/Paths.xaml @@ -8,8 +8,11 @@ +