From 710b3b28f363d993da423aa98db3e74b2305b2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Pokorn=C3=BD?= Date: Fri, 2 Aug 2024 10:26:13 +0200 Subject: [PATCH 1/2] Prepare NumericUpDown.FormatString change unit test. --- .../NumericUpDownTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs b/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs index 24f246d188d..10139be0d45 100644 --- a/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs +++ b/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs @@ -62,6 +62,24 @@ public void Increment_Decrement_Tests(decimal min, decimal max, decimal? value, 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 From 705151f6f96f22be72d99c0cf1788f4bc77ceaf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Pokorn=C3=BD?= Date: Fri, 2 Aug 2024 10:29:18 +0200 Subject: [PATCH 2/2] Apply NumericUpDown.FormatString immediately on change. --- src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs index 0edc7984949..f0dde6925d5 100644 --- a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs +++ b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs @@ -479,7 +479,7 @@ protected virtual void OnFormatStringChanged(string? oldValue, string? newValue) { if (IsInitialized) { - SyncTextAndValueProperties(false, null); + SyncTextAndValueProperties(false, null, true); } }