From 12d7ff1bfc6296f79c0f8bfb03e8959a7900ce87 Mon Sep 17 00:00:00 2001 From: dpse Date: Wed, 17 Dec 2025 01:45:40 +0100 Subject: [PATCH] Apply NumberFormat changes to NumericUpDown (#20248) * Add NumericUpDown NumberFormat failing test * Force text update when NumberFormat has changed --------- Co-authored-by: Julien Lebosquain --- .../NumericUpDown/NumericUpDown.cs | 2 +- .../NumericUpDownTests.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs index d9cc92f0e6..188497d230 100644 --- a/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs +++ b/src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs @@ -450,7 +450,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 f03bd5b633..42e58f4d8d 100644 --- a/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs +++ b/tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Reactive.Subjects; using Avalonia.Controls.Templates; @@ -80,6 +81,26 @@ namespace Avalonia.Controls.UnitTests }); } + [Fact] + public void NumberFormat_Is_Applied_Immediately() + { + RunTest((control, textbox) => + { + const decimal value = 10.11m; + var initialNumberFormat = new NumberFormatInfo { NumberDecimalSeparator = "." }; + var newNumberFormat = new NumberFormatInfo { NumberDecimalSeparator = ";" }; + + // Establish and verify initial conditions. + control.NumberFormat = initialNumberFormat; + control.Value = value; + Assert.Equal(value.ToString(initialNumberFormat), control.Text); + + // Check that NumberFormat is applied. + control.NumberFormat = newNumberFormat; + Assert.Equal(value.ToString(newNumberFormat), 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