using System; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Interactivity; namespace Avalonia.Controls { public enum Location { Left, Right } /// /// Represents a spinner control that includes two Buttons. /// public class ButtonSpinner : Spinner { /// /// Defines the property. /// public static readonly StyledProperty AllowSpinProperty = AvaloniaProperty.Register(nameof(AllowSpin), true); /// /// Defines the property. /// public static readonly StyledProperty ShowButtonSpinnerProperty = AvaloniaProperty.Register(nameof(ShowButtonSpinner), true); /// /// Defines the property. /// public static readonly StyledProperty ButtonSpinnerLocationProperty = AvaloniaProperty.Register(nameof(ButtonSpinnerLocation), Location.Right); private Button _decreaseButton; /// /// Gets or sets the DecreaseButton template part. /// private Button DecreaseButton { get { return _decreaseButton; } set { if (_decreaseButton != null) { _decreaseButton.Click -= OnButtonClick; } _decreaseButton = value; if (_decreaseButton != null) { _decreaseButton.Click += OnButtonClick; } } } private Button _increaseButton; /// /// Gets or sets the IncreaseButton template part. /// private Button IncreaseButton { get { return _increaseButton; } set { if (_increaseButton != null) { _increaseButton.Click -= OnButtonClick; } _increaseButton = value; if (_increaseButton != null) { _increaseButton.Click += OnButtonClick; } } } /// /// Initializes static members of the class. /// static ButtonSpinner() { AllowSpinProperty.Changed.Subscribe(AllowSpinChanged); PseudoClass(ButtonSpinnerLocationProperty, location => location == Location.Left, ":left"); PseudoClass(ButtonSpinnerLocationProperty, location => location == Location.Right, ":right"); } /// /// Gets or sets a value indicating whether the should allow to spin. /// public bool AllowSpin { get { return GetValue(AllowSpinProperty); } set { SetValue(AllowSpinProperty, value); } } /// /// Gets or sets a value indicating whether the spin buttons should be shown. /// public bool ShowButtonSpinner { get { return GetValue(ShowButtonSpinnerProperty); } set { SetValue(ShowButtonSpinnerProperty, value); } } /// /// Gets or sets current location of the . /// public Location ButtonSpinnerLocation { get { return GetValue(ButtonSpinnerLocationProperty); } set { SetValue(ButtonSpinnerLocationProperty, value); } } /// protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { IncreaseButton = e.NameScope.Find