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