Skip to content

Commit

Permalink
Reintroduce coercion to NumericUpDown.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys committed Nov 24, 2019
1 parent 1616e76 commit 4065742
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class NumericUpDown : TemplatedControl
/// Defines the <see cref="Increment"/> property.
/// </summary>
public static readonly StyledProperty<double> IncrementProperty =
AvaloniaProperty.Register<NumericUpDown, double>(nameof(Increment), 1.0d/*, validate: OnCoerceIncrement*/);
AvaloniaProperty.Register<NumericUpDown, double>(nameof(Increment), 1.0d, coerce: OnCoerceIncrement);

/// <summary>
/// Defines the <see cref="IsReadOnly"/> property.
Expand All @@ -70,13 +70,13 @@ public class NumericUpDown : TemplatedControl
/// Defines the <see cref="Maximum"/> property.
/// </summary>
public static readonly StyledProperty<double> MaximumProperty =
AvaloniaProperty.Register<NumericUpDown, double>(nameof(Maximum), double.MaxValue/*, validate: OnCoerceMaximum*/);
AvaloniaProperty.Register<NumericUpDown, double>(nameof(Maximum), double.MaxValue, coerce: OnCoerceMaximum);

/// <summary>
/// Defines the <see cref="Minimum"/> property.
/// </summary>
public static readonly StyledProperty<double> MinimumProperty =
AvaloniaProperty.Register<NumericUpDown, double>(nameof(Minimum), double.MinValue/*, validate: OnCoerceMinimum*/);
AvaloniaProperty.Register<NumericUpDown, double>(nameof(Minimum), double.MinValue, coerce: OnCoerceMinimum);

/// <summary>
/// Defines the <see cref="ParsingNumberStyle"/> property.
Expand Down Expand Up @@ -738,19 +738,34 @@ private void SetValueInternal(double value)
}
}

private static double OnCoerceMaximum(NumericUpDown upDown, double value)
private static double OnCoerceMaximum(IAvaloniaObject instance, double value)
{
return upDown.OnCoerceMaximum(value);
if (instance is NumericUpDown upDown)
{
return upDown.OnCoerceMaximum(value);
}

return value;
}

private static double OnCoerceMinimum(NumericUpDown upDown, double value)
private static double OnCoerceMinimum(IAvaloniaObject instance, double value)
{
return upDown.OnCoerceMinimum(value);
if (instance is NumericUpDown upDown)
{
return upDown.OnCoerceMinimum(value);
}

return value;
}

private static double OnCoerceIncrement(NumericUpDown upDown, double value)
private static double OnCoerceIncrement(IAvaloniaObject instance, double value)
{
return upDown.OnCoerceIncrement(value);
if (instance is NumericUpDown upDown)
{
return upDown.OnCoerceIncrement(value);
}

return value;
}

private void TextBoxOnTextChanged()
Expand Down

0 comments on commit 4065742

Please sign in to comment.