From ac8b5561a5bca683254bc5b52af7d7a58434548b Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 18 Jul 2021 14:11:19 +0800 Subject: [PATCH] hc:NumericUpDown support for Validation --- .../Controls/Input/NumericUpDown.cs | 28 +++++++++++++++---- .../Styles/Base/NumericUpDownBaseStyle.xaml | 2 ++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs index aeab72b3..210257f6 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs @@ -112,12 +112,28 @@ namespace HandyControl.Controls _updateText = true; return; } - if (double.TryParse(_textBox.Text, out var value)) + + _updateText = false; + + if (string.IsNullOrWhiteSpace(_textBox.Text)) { - _updateText = false; - Value = value; - _updateText = true; + Value = 0; + + SetCurrentValue(ErrorStrProperty, string.Empty); + SetCurrentValue(IsErrorProperty, false); } + else if (double.TryParse(_textBox.Text, out var value)) + { + Value = value; + + if (Validation.GetHasError(this)) + { + SetCurrentValue(ErrorStrProperty, Validation.GetErrors(this)[0].ErrorContent); + SetCurrentValue(IsErrorProperty, true); + } + } + + _updateText = true; } private void PreviewTextInputHandler(object sender, TextCompositionEventArgs e) => UpdateData(); @@ -496,8 +512,8 @@ namespace HandyControl.Controls } } - IsError = !result.Data; - ErrorStr = result.Message; + SetCurrentValue(ErrorStrProperty, result.Message); + SetCurrentValue(IsErrorProperty, !result.Data); return result.Data; } } diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/NumericUpDownBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/NumericUpDownBaseStyle.xaml index 0109be81..036616d5 100644 --- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/NumericUpDownBaseStyle.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/NumericUpDownBaseStyle.xaml @@ -21,6 +21,7 @@ + @@ -285,6 +286,7 @@