From e109f73ac312c981358fdbe03f9c3ccc5b778fee Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sun, 5 Jan 2020 20:45:57 +0800 Subject: [PATCH] Update NumericUpDown.cs --- .../Controls/Input/NumericUpDown.cs | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs index dbce3b48..eac6fd1a 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs @@ -31,8 +31,7 @@ namespace HandyControl.Controls { CommandBindings.Add(new CommandBinding(ControlCommands.Prev, (s, e) => { - if (IsReadOnly) - return; + if (IsReadOnly) return; Value += Increment; _textBox.Text = CurrentText; @@ -40,9 +39,7 @@ namespace HandyControl.Controls })); CommandBindings.Add(new CommandBinding(ControlCommands.Next, (s, e) => { - if (IsReadOnly) - return; - + if (IsReadOnly) return; Value -= Increment; _textBox.Text = CurrentText; @@ -50,8 +47,7 @@ namespace HandyControl.Controls })); CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) => { - if (IsReadOnly) - return; + if (IsReadOnly) return; SetCurrentValue(ValueProperty, ValueBoxes.Double0Box); _textBox.Text = string.Empty; @@ -116,8 +112,7 @@ namespace HandyControl.Controls private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e) { - if (IsReadOnly) - return; + if (IsReadOnly) return; if (e.Key == Key.Up) { @@ -135,7 +130,7 @@ namespace HandyControl.Controls { base.OnMouseWheel(e); - if (_textBox.IsFocused&&IsReadOnly==false) + if (_textBox.IsFocused && !IsReadOnly) { Value += e.Delta > 0 ? Increment : -Increment; _textBox.Text = CurrentText; @@ -375,22 +370,21 @@ namespace HandyControl.Controls set => SetValue(ShowClearButtonProperty, value); } + /// + /// 标识 IsReadOnly 依赖属性。 + /// + public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register( + "IsReadOnly", typeof(bool), typeof(NumericUpDown), new PropertyMetadata(ValueBoxes.FalseBox)); + /// /// 获取或设置一个值,该值指示NumericUpDown是否只读。 /// public bool IsReadOnly { - get => (bool)GetValue(IsReadOnlyProperty); + get => (bool) GetValue(IsReadOnlyProperty); set => SetValue(IsReadOnlyProperty, value); } - /// - /// 标识 IsReadOnly 依赖属性。 - /// - public static readonly DependencyProperty IsReadOnlyProperty = - DependencyProperty.Register(nameof(IsReadOnly), typeof(bool), typeof(NumericUpDown), new PropertyMetadata(default(bool))); - - public Func> VerifyFunc { get; set; } public virtual bool VerifyData()