Browse Source

Switch RangeBase.ValueChanged from generic RoutedPropertyChangedEventArgs<double> to RangeBaseValueChangedEventArgs

This follows the WinUI pattern and makes a bit more sense. It is also similar to what is done with TextBox events as well.
pull/11544/head
robloo 3 years ago
parent
commit
68134c925f
  1. 8
      src/Avalonia.Controls/Primitives/RangeBase.cs
  2. 47
      src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs

8
src/Avalonia.Controls/Primitives/RangeBase.cs

@ -45,14 +45,14 @@ namespace Avalonia.Controls.Primitives
/// <summary>
/// Defines the <see cref="ValueChanged"/> event.
/// </summary>
public static readonly RoutedEvent<RoutedPropertyChangedEventArgs<double>> ValueChangedEvent =
RoutedEvent.Register<RangeBase, RoutedPropertyChangedEventArgs<double>>(
public static readonly RoutedEvent<RangeBaseValueChangedEventArgs> ValueChangedEvent =
RoutedEvent.Register<RangeBase, RangeBaseValueChangedEventArgs>(
nameof(ValueChanged), RoutingStrategies.Bubble);
/// <summary>
/// Occurs when the <see cref="Value"/> property changes.
/// </summary>
public event EventHandler<RoutedPropertyChangedEventArgs<double>>? ValueChanged
public event EventHandler<RangeBaseValueChangedEventArgs>? ValueChanged
{
add => AddHandler(ValueChangedEvent, value);
remove => RemoveHandler(ValueChangedEvent, value);
@ -163,7 +163,7 @@ namespace Avalonia.Controls.Primitives
}
else if (change.Property == ValueProperty)
{
var valueChangedEventArgs = new RoutedPropertyChangedEventArgs<double>(
var valueChangedEventArgs = new RangeBaseValueChangedEventArgs(
change.GetOldValue<double>(),
change.GetNewValue<double>(),
ValueChangedEvent);

47
src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs

@ -0,0 +1,47 @@
using Avalonia.Interactivity;
namespace Avalonia.Controls.Primitives
{
/// <summary>
/// Provides data specific to a <see cref="RangeBase.ValueChanged"/> event.
/// </summary>
public class RangeBaseValueChangedEventArgs : RoutedEventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="RangeBaseValueChangedEventArgs"/> class.
/// </summary>
/// <param name="oldValue">The old property value.</param>
/// <param name="newValue">The new property value.</param>
/// <param name="routedEvent">The routed event associated with these event args.</param>
public RangeBaseValueChangedEventArgs(double oldValue, double newValue, RoutedEvent? routedEvent)
: base(routedEvent)
{
OldValue = oldValue;
NewValue = newValue;
}
/// <summary>
/// Initializes a new instance of the <see cref="RangeBaseValueChangedEventArgs"/> class.
/// </summary>
/// <param name="oldValue">The old property value.</param>
/// <param name="newValue">The new property value.</param>
/// <param name="routedEvent">The routed event associated with these event args.</param>
/// <param name="source">The source object that raised the routed event.</param>
public RangeBaseValueChangedEventArgs(double oldValue, double newValue, RoutedEvent? routedEvent, object? source)
: base(routedEvent, source)
{
OldValue = oldValue;
NewValue = newValue;
}
/// <summary>
/// Gets the old value of the property.
/// </summary>
public double OldValue { get; init; }
/// <summary>
/// Gets the new value of the property.
/// </summary>
public double NewValue { get; init; }
}
}
Loading…
Cancel
Save