// Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Interactivity; namespace Avalonia.Controls { /// /// A control that lets the user select from a range of values by moving a Thumb control along a Track. /// public class Slider : RangeBase { /// /// Defines the property. /// public static readonly StyledProperty OrientationProperty = AvaloniaProperty.Register(nameof(Orientation), Orientation.Horizontal); /// /// Defines the property. /// public static readonly StyledProperty IsSnapToTickEnabledProperty = AvaloniaProperty.Register(nameof(IsSnapToTickEnabled), false); /// /// Defines the property. /// public static readonly StyledProperty TickFrequencyProperty = AvaloniaProperty.Register(nameof(TickFrequency), 0.0); // Slider required parts private Track _track; private Button _decreaseButton; private Button _increaseButton; /// /// Initializes static members of the class. /// static Slider() { PseudoClass(OrientationProperty, o => o == Avalonia.Controls.Orientation.Vertical, ":vertical"); PseudoClass(OrientationProperty, o => o == Avalonia.Controls.Orientation.Horizontal, ":horizontal"); Thumb.DragStartedEvent.AddClassHandler(x => x.OnThumbDragStarted, RoutingStrategies.Bubble); Thumb.DragDeltaEvent.AddClassHandler(x => x.OnThumbDragDelta, RoutingStrategies.Bubble); Thumb.DragCompletedEvent.AddClassHandler(x => x.OnThumbDragCompleted, RoutingStrategies.Bubble); } /// /// Instantiates a new instance of the class. /// public Slider() { } /// /// Gets or sets the orientation of a . /// public Orientation Orientation { get { return GetValue(OrientationProperty); } set { SetValue(OrientationProperty, value); } } /// /// Gets or sets a value that indicates whether the automatically moves the to the closest tick mark. /// public bool IsSnapToTickEnabled { get { return GetValue(IsSnapToTickEnabledProperty); } set { SetValue(IsSnapToTickEnabledProperty, value); } } /// /// Gets or sets the interval between tick marks. /// public double TickFrequency { get { return GetValue(TickFrequencyProperty); } set { SetValue(TickFrequencyProperty, value); } } /// protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { if (_decreaseButton != null) { _decreaseButton.Click -= DecreaseClick; } if (_increaseButton != null) { _increaseButton.Click -= IncreaseClick; } _decreaseButton = e.NameScope.Find