From 0f2cb24a3be00095128f8f9bd6e83554e6d3aa74 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Wed, 7 Aug 2019 22:58:26 +0800 Subject: [PATCH] Update NumericUpDown.cs --- .../Controls/Input/NumericUpDown.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs index 5f8f3f48..f4b8aa78 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs @@ -1,6 +1,7 @@ using System; using System.Windows; using System.Windows.Controls; +using System.Windows.Documents; using System.Windows.Input; using HandyControl.Data; using HandyControl.Interactivity; @@ -65,7 +66,8 @@ namespace HandyControl.Controls { if (_textBox != null) { - _textBox.TextChanged -= TextBox_TextChanged; + TextCompositionManager.RemovePreviewTextInputHandler(_textBox, PreviewTextInputHandler); + _textBox.TextChanged -= _textBox_TextChanged; _textBox.PreviewKeyDown -= TextBox_PreviewKeyDown; _textBox.LostFocus -= TextBox_LostFocus; } @@ -76,13 +78,27 @@ namespace HandyControl.Controls if (_textBox != null) { - _textBox.TextChanged += TextBox_TextChanged; + TextCompositionManager.AddPreviewTextInputHandler(_textBox, PreviewTextInputHandler); + _textBox.TextChanged += _textBox_TextChanged; _textBox.PreviewKeyDown += TextBox_PreviewKeyDown; _textBox.LostFocus += TextBox_LostFocus; _textBox.Text = CurrentText; } } + private void _textBox_TextChanged(object sender, TextChangedEventArgs e) => UpdateData(); + + private void UpdateData() + { + if (!VerifyData()) return; + if (double.TryParse(_textBox.Text, out var value)) + { + Value = value; + } + } + + private void PreviewTextInputHandler(object sender, TextCompositionEventArgs e) => UpdateData(); + private void TextBox_LostFocus(object sender, RoutedEventArgs e) { if (IsError) return; @@ -103,15 +119,6 @@ namespace HandyControl.Controls } } - private void TextBox_TextChanged(object sender, TextChangedEventArgs e) - { - if (!VerifyData()) return; - if (double.TryParse(_textBox.Text, out var value)) - { - Value = value; - } - } - protected override void OnMouseWheel(MouseWheelEventArgs e) { base.OnMouseWheel(e);