diff --git a/src/MaterialDesignThemes.Wpf/UpDownBase.cs b/src/MaterialDesignThemes.Wpf/UpDownBase.cs index 5e56db6edd..8e82ba1889 100644 --- a/src/MaterialDesignThemes.Wpf/UpDownBase.cs +++ b/src/MaterialDesignThemes.Wpf/UpDownBase.cs @@ -215,10 +215,8 @@ private void OnTextBoxFocusLost(object sender, EventArgs e) { SetCurrentValue(ValueProperty, value); } - else - { - textBoxField.Text = Value?.ToString(); - } + //NB: Because setting ValueProperty will coerce the value, we re-assign back to the textbox here. + textBoxField.Text = Value?.ToString(); } } diff --git a/tests/MaterialDesignThemes.UITests/WPF/UpDownControls/DecimalUpDownTests.cs b/tests/MaterialDesignThemes.UITests/WPF/UpDownControls/DecimalUpDownTests.cs index 522450e680..ae00c250a4 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/UpDownControls/DecimalUpDownTests.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/UpDownControls/DecimalUpDownTests.cs @@ -32,6 +32,8 @@ await Wait.For(async () => Assert.Equal("1", await textBox.GetText()); Assert.Equal(1, await numericUpDown.GetValue()); }); + + recorder.Success(); } [Fact] @@ -63,6 +65,8 @@ await Wait.For(async () => }); Assert.True(await plusButton.GetIsEnabled()); + + recorder.Success(); } [Fact] @@ -94,6 +98,8 @@ await Wait.For(async () => }); Assert.True(await minusButton.GetIsEnabled()); + + recorder.Success(); } [Fact] @@ -116,6 +122,8 @@ public async Task MaxAndMinAssignments_CoerceValueToBeInRange() Assert.Equal(3, await numericUpDown.GetValue()); Assert.Equal(3, await numericUpDown.GetMinimum()); Assert.Equal(3, await numericUpDown.GetMaximum()); + + recorder.Success(); } [Fact] @@ -147,4 +155,63 @@ public async Task InternalTextBoxIsFocused_WhenGettingKeyboardFocus() recorder.Success(); } + + [Fact] + [Description("Issue 3781")] + public async Task IncreaseButtonClickWhenTextIsAboveMaximum_DoesNotIncreaseValue() + { + await using var recorder = new TestRecorder(App); + + var stackPanel = await LoadXaml(""" + + +