Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply NumericUpDown.FormatString changes immediately. #16575

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ protected virtual void OnFormatStringChanged(string? oldValue, string? newValue)
{
if (IsInitialized)
{
SyncTextAndValueProperties(false, null);
SyncTextAndValueProperties(false, null, true);
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Avalonia.Controls.UnitTests/NumericUpDownTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<object[]> Increment_Decrement_TestData()
{
// if min and max are not defined and value was null, 0 should be ne new value after spin
Expand Down
Loading