diff --git a/samples/ControlCatalog/Pages/SliderPage.xaml b/samples/ControlCatalog/Pages/SliderPage.xaml index 9cdefa812f..58f7b881fe 100644 --- a/samples/ControlCatalog/Pages/SliderPage.xaml +++ b/samples/ControlCatalog/Pages/SliderPage.xaml @@ -9,7 +9,7 @@ + Width="300"/> IsDirectionReversedProperty = AvaloniaProperty.Register(nameof(IsDirectionReversed)); - public static readonly StyledProperty IgnoreThumbDragProperty = - AvaloniaProperty.Register(nameof(IsThumbDragHandled)); - private double _minimum; private double _maximum = 100.0; private double _value; static Track() { - ThumbProperty.Changed.AddClassHandler((x, e) => x.ThumbChanged(e)); + ThumbProperty.Changed.AddClassHandler((x,e) => x.ThumbChanged(e)); IncreaseButtonProperty.Changed.AddClassHandler((x, e) => x.ButtonChanged(e)); DecreaseButtonProperty.Changed.AddClassHandler((x, e) => x.ButtonChanged(e)); AffectsArrange(MinimumProperty, MaximumProperty, ValueProperty, OrientationProperty); @@ -116,12 +113,6 @@ namespace Avalonia.Controls.Primitives set { SetValue(IsDirectionReversedProperty, value); } } - public bool IsThumbDragHandled - { - get { return GetValue(IgnoreThumbDragProperty); } - set { SetValue(IgnoreThumbDragProperty, value); } - } - private double ThumbCenterOffset { get; set; } private double Density { get; set; } @@ -431,9 +422,6 @@ namespace Avalonia.Controls.Primitives private void ThumbDragged(object sender, VectorEventArgs e) { - if (IsThumbDragHandled) - return; - Value = MathUtilities.Clamp( Value + ValueFromDistance(e.Vector.X, e.Vector.Y), Minimum, diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index 4efcbd6a2d..e92c8faf20 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -1,10 +1,9 @@ using System; -using Avalonia.Controls.Mixins; using Avalonia.Controls.Primitives; +using Avalonia.Data; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Layout; -using Avalonia.Utilities; namespace Avalonia.Controls { @@ -32,24 +31,18 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(TickFrequency), 0.0); // Slider required parts - private bool _isDragging = false; private Track _track; private Button _decreaseButton; private Button _increaseButton; - private IDisposable _decreaseButtonPressDispose; - private IDisposable _decreaseButtonReleaseDispose; - private IDisposable _increaseButtonSubscription; - private IDisposable _increaseButtonReleaseDispose; - private IDisposable _pointerMovedDispose; /// /// Initializes static members of the class. /// static Slider() { - PressedMixin.Attach(); OrientationProperty.OverrideDefaultValue(typeof(Slider), Orientation.Horizontal); Thumb.DragStartedEvent.AddClassHandler((x, e) => x.OnThumbDragStarted(e), RoutingStrategies.Bubble); + Thumb.DragDeltaEvent.AddClassHandler((x, e) => x.OnThumbDragDelta(e), RoutingStrategies.Bubble); Thumb.DragCompletedEvent.AddClassHandler((x, e) => x.OnThumbDragCompleted(e), RoutingStrategies.Bubble); } @@ -91,70 +84,54 @@ namespace Avalonia.Controls /// protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { - _decreaseButtonPressDispose?.Dispose(); - _decreaseButtonReleaseDispose?.Dispose(); - _increaseButtonSubscription?.Dispose(); - _increaseButtonReleaseDispose?.Dispose(); - _pointerMovedDispose?.Dispose(); + if (_decreaseButton != null) + { + _decreaseButton.Click -= DecreaseClick; + } + + if (_increaseButton != null) + { + _increaseButton.Click -= IncreaseClick; + } _decreaseButton = e.NameScope.Find