using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Reactive;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace Avalonia.Controls
{
public enum Location
{
Left,
Right
}
///
/// Represents a spinner control that includes two Buttons.
///
[TemplatePart("PART_DecreaseButton", typeof(Button))]
[TemplatePart("PART_IncreaseButton", typeof(Button))]
[PseudoClasses(":left", ":right")]
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);
public ButtonSpinner()
{
UpdatePseudoClasses(ButtonSpinnerLocation);
}
private Button? _decreaseButton;
///
/// Gets or sets the DecreaseButton template part.
///
private Button? DecreaseButton
{
get => _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 => _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);
}
///
/// Gets or sets a value indicating whether the should allow to spin.
///
public bool AllowSpin
{
get => GetValue(AllowSpinProperty);
set => SetValue(AllowSpinProperty, value);
}
///
/// Gets or sets a value indicating whether the spin buttons should be shown.
///
public bool ShowButtonSpinner
{
get => GetValue(ShowButtonSpinnerProperty);
set => SetValue(ShowButtonSpinnerProperty, value);
}
///
/// Gets or sets current location of the .
///
public Location ButtonSpinnerLocation
{
get => GetValue(ButtonSpinnerLocationProperty);
set => SetValue(ButtonSpinnerLocationProperty, value);
}
///
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
IncreaseButton = e.NameScope.Find