From d1ea3ff0261776a8f148bcc57964ecd1846564f4 Mon Sep 17 00:00:00 2001 From: pokorpa <37274481+pokorpa@users.noreply.github.com> Date: Sat, 3 Aug 2024 11:01:39 +0200 Subject: [PATCH] Apply NumericUpDown.FormatString changes immediately. (#16575) * Prepare NumericUpDown.FormatString change unit test. * Apply NumericUpDown.FormatString immediately on change. --- .../NumericUpDown/NumericUpDown.cs | 2 +- .../NumericUpDownTests.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs index 0edc798494..f0dde6925d 100644 --- a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs +++ b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs @@ -479,7 +479,7 @@ namespace Avalonia.Controls { if (IsInitialized) { - SyncTextAndValueProperties(false, null); + SyncTextAndValueProperties(false, null, true); } } diff --git a/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs b/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs index 24f246d188..10139be0d4 100644 --- a/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs +++ b/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs @@ -62,6 +62,24 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(control.Value, expected); } + [Fact] + public void FormatString_Is_Applied_Immediately() + { + RunTest((control, textbox) => + { + const decimal value = 10.11m; + + // Establish and verify initial conditions. + control.FormatString = "F0"; + control.Value = value; + Assert.Equal(value.ToString("F0"), control.Text); + + // Check that FormatString is applied. + control.FormatString = "F2"; + Assert.Equal(value.ToString("F2"), control.Text); + }); + } + public static IEnumerable Increment_Decrement_TestData() { // if min and max are not defined and value was null, 0 should be ne new value after spin