Skip to content

Commit ffebacd

Browse files
authored
fix(controls): Re-round NumberBox Value on MaxDecimalPlaces change (#1738)
1 parent 505c44d commit ffebacd

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/Wpf.Ui/Controls/NumberBox/NumberBox.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public partial class NumberBox : Wpf.Ui.Controls.TextBox
5656
nameof(MaxDecimalPlaces),
5757
typeof(int),
5858
typeof(NumberBox),
59-
new PropertyMetadata(6)
59+
new PropertyMetadata(6, OnMaxDecimalPlacesChanged)
6060
);
6161

6262
/// <summary>Identifies the <see cref="SmallChange"/> dependency property.</summary>
@@ -524,6 +524,19 @@ private static void OnNumberFormatterChanged(DependencyObject d, DependencyPrope
524524
}
525525
}
526526

527+
private static void OnMaxDecimalPlacesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
528+
{
529+
if (d is not NumberBox numberBox)
530+
{
531+
return;
532+
}
533+
534+
if (numberBox.Value is double currentValue)
535+
{
536+
numberBox.SetCurrentValue(ValueProperty, Math.Round(currentValue, numberBox.MaxDecimalPlaces));
537+
}
538+
}
539+
527540
private static partial class Debug
528541
{
529542
public static partial void InfoWriteLine(string debugLine);

0 commit comments

Comments
 (0)