From 68134c925fb3ff9acf78725b0cdc4a3cb77554e8 Mon Sep 17 00:00:00 2001 From: robloo Date: Sat, 27 May 2023 19:48:07 -0400 Subject: [PATCH 1/4] Switch RangeBase.ValueChanged from generic RoutedPropertyChangedEventArgs 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. --- src/Avalonia.Controls/Primitives/RangeBase.cs | 8 ++-- .../RangeBaseValueChangedEventArgs.cs | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs diff --git a/src/Avalonia.Controls/Primitives/RangeBase.cs b/src/Avalonia.Controls/Primitives/RangeBase.cs index ebf7879412..33ab78b66f 100644 --- a/src/Avalonia.Controls/Primitives/RangeBase.cs +++ b/src/Avalonia.Controls/Primitives/RangeBase.cs @@ -45,14 +45,14 @@ namespace Avalonia.Controls.Primitives /// /// Defines the event. /// - public static readonly RoutedEvent> ValueChangedEvent = - RoutedEvent.Register>( + public static readonly RoutedEvent ValueChangedEvent = + RoutedEvent.Register( nameof(ValueChanged), RoutingStrategies.Bubble); /// /// Occurs when the property changes. /// - public event EventHandler>? ValueChanged + public event EventHandler? 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( + var valueChangedEventArgs = new RangeBaseValueChangedEventArgs( change.GetOldValue(), change.GetNewValue(), ValueChangedEvent); diff --git a/src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs b/src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs new file mode 100644 index 0000000000..ce1ac90bc6 --- /dev/null +++ b/src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs @@ -0,0 +1,47 @@ +using Avalonia.Interactivity; + +namespace Avalonia.Controls.Primitives +{ + /// + /// Provides data specific to a event. + /// + public class RangeBaseValueChangedEventArgs : RoutedEventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// The old property value. + /// The new property value. + /// The routed event associated with these event args. + public RangeBaseValueChangedEventArgs(double oldValue, double newValue, RoutedEvent? routedEvent) + : base(routedEvent) + { + OldValue = oldValue; + NewValue = newValue; + } + + /// + /// Initializes a new instance of the class. + /// + /// The old property value. + /// The new property value. + /// The routed event associated with these event args. + /// The source object that raised the routed event. + public RangeBaseValueChangedEventArgs(double oldValue, double newValue, RoutedEvent? routedEvent, object? source) + : base(routedEvent, source) + { + OldValue = oldValue; + NewValue = newValue; + } + + /// + /// Gets the old value of the property. + /// + public double OldValue { get; init; } + + /// + /// Gets the new value of the property. + /// + public double NewValue { get; init; } + } +} From 545e9051bd89083f9d272703a5df475fbad89920 Mon Sep 17 00:00:00 2001 From: robloo Date: Sat, 27 May 2023 19:48:55 -0400 Subject: [PATCH 2/4] Remove generic RoutedPropertyChangedEventArgs --- .../RoutedPropertyChangedEventArgs.cs | 46 ------------------- 1 file changed, 46 deletions(-) delete mode 100644 src/Avalonia.Base/Interactivity/RoutedPropertyChangedEventArgs.cs diff --git a/src/Avalonia.Base/Interactivity/RoutedPropertyChangedEventArgs.cs b/src/Avalonia.Base/Interactivity/RoutedPropertyChangedEventArgs.cs deleted file mode 100644 index 22134b518d..0000000000 --- a/src/Avalonia.Base/Interactivity/RoutedPropertyChangedEventArgs.cs +++ /dev/null @@ -1,46 +0,0 @@ -namespace Avalonia.Interactivity -{ - /// - /// Provides both old and new property values with a routed event. - /// - /// The type of values. - public class RoutedPropertyChangedEventArgs : RoutedEventArgs - { - /// - /// Initializes a new instance of the class. - /// - /// The old property value. - /// The new property value. - /// The routed event associated with these event args. - public RoutedPropertyChangedEventArgs(T oldValue, T newValue, RoutedEvent? routedEvent) - : base(routedEvent) - { - OldValue = oldValue; - NewValue = newValue; - } - - /// - /// Initializes a new instance of the class. - /// - /// The old property value. - /// The new property value. - /// The routed event associated with these event args. - /// The source object that raised the routed event. - public RoutedPropertyChangedEventArgs(T oldValue, T newValue, RoutedEvent? routedEvent, object? source) - : base(routedEvent, source) - { - OldValue = oldValue; - NewValue = newValue; - } - - /// - /// Gets the old value of the property. - /// - public T OldValue { get; init; } - - /// - /// Gets the new value of the property. - /// - public T NewValue { get; init; } - } -} From 0d1ef8f7b62c037dafd53d9afdcec6a7d5c9f869 Mon Sep 17 00:00:00 2001 From: robloo Date: Sat, 27 May 2023 19:49:19 -0400 Subject: [PATCH 3/4] Add comments to TextChangedEventArgs and TextChangingEventArgs --- src/Avalonia.Controls/TextChangedEventArgs.cs | 11 ++++++++++- src/Avalonia.Controls/TextChangingEventArgs.cs | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/TextChangedEventArgs.cs b/src/Avalonia.Controls/TextChangedEventArgs.cs index 1418154256..f614d2d760 100644 --- a/src/Avalonia.Controls/TextChangedEventArgs.cs +++ b/src/Avalonia.Controls/TextChangedEventArgs.cs @@ -3,15 +3,24 @@ namespace Avalonia.Controls { /// - /// Provides data specific to a TextChanged event. + /// Provides data specific to a event. /// public class TextChangedEventArgs : RoutedEventArgs { + /// + /// Initializes a new instance of the class. + /// + /// The routed event associated with these event args. public TextChangedEventArgs(RoutedEvent? routedEvent) : base (routedEvent) { } + /// + /// Initializes a new instance of the class. + /// + /// The routed event associated with these event args. + /// The source object that raised the routed event. public TextChangedEventArgs(RoutedEvent? routedEvent, Interactive? source) : base(routedEvent, source) { diff --git a/src/Avalonia.Controls/TextChangingEventArgs.cs b/src/Avalonia.Controls/TextChangingEventArgs.cs index 09e7d5b258..6ec5afd030 100644 --- a/src/Avalonia.Controls/TextChangingEventArgs.cs +++ b/src/Avalonia.Controls/TextChangingEventArgs.cs @@ -3,15 +3,24 @@ namespace Avalonia.Controls { /// - /// Provides data specific to a TextChanging event. + /// Provides data specific to a event. /// public class TextChangingEventArgs : RoutedEventArgs { + /// + /// Initializes a new instance of the class. + /// + /// The routed event associated with these event args. public TextChangingEventArgs(RoutedEvent? routedEvent) : base (routedEvent) { } + /// + /// Initializes a new instance of the class. + /// + /// The routed event associated with these event args. + /// The source object that raised the routed event. public TextChangingEventArgs(RoutedEvent? routedEvent, Interactive? source) : base(routedEvent, source) { From 4bcf08a9dc70efe18cc48fd6ca01679195bec683 Mon Sep 17 00:00:00 2001 From: robloo Date: Sat, 27 May 2023 20:00:37 -0400 Subject: [PATCH 4/4] Update RangeBaseValueChangedEventArgs comments --- .../Primitives/RangeBaseValueChangedEventArgs.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs b/src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs index ce1ac90bc6..480e82e4fc 100644 --- a/src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs +++ b/src/Avalonia.Controls/Primitives/RangeBaseValueChangedEventArgs.cs @@ -10,8 +10,8 @@ namespace Avalonia.Controls.Primitives /// /// Initializes a new instance of the class. /// - /// The old property value. - /// The new property value. + /// The old value of the range value property. + /// The new value of the range value property. /// The routed event associated with these event args. public RangeBaseValueChangedEventArgs(double oldValue, double newValue, RoutedEvent? routedEvent) : base(routedEvent) @@ -23,8 +23,8 @@ namespace Avalonia.Controls.Primitives /// /// Initializes a new instance of the class. /// - /// The old property value. - /// The new property value. + /// The old value of the range value property. + /// The new value of the range value property. /// The routed event associated with these event args. /// The source object that raised the routed event. public RangeBaseValueChangedEventArgs(double oldValue, double newValue, RoutedEvent? routedEvent, object? source) @@ -35,12 +35,12 @@ namespace Avalonia.Controls.Primitives } /// - /// Gets the old value of the property. + /// Gets the old value of the range value property. /// public double OldValue { get; init; } /// - /// Gets the new value of the property. + /// Gets the new value of the range value property. /// public double NewValue { get; init; } }