Browse Source

Apply NumberFormat changes to NumericUpDown (#20248)

* Add NumericUpDown NumberFormat failing test

* Force text update when NumberFormat has changed

---------

Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
release/11.3.10
dpse 2 months ago
committed by Julien Lebosquain
parent
commit
7d16082e96
No known key found for this signature in database GPG Key ID: 1833CAD10ACC46FD
  1. 2
      src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs
  2. 21
      tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs

2
src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs

@ -468,7 +468,7 @@ namespace Avalonia.Controls
{
if (IsInitialized)
{
SyncTextAndValueProperties(false, null);
SyncTextAndValueProperties(false, null, true);
}
}

21
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<object[]> Increment_Decrement_TestData()
{
// if min and max are not defined and value was null, 0 should be ne new value after spin

Loading…
Cancel
Save