using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Styling;
using Irihi.Avalonia.Shared.Helpers;
using System.Windows.Input;
namespace Ursa.Controls;
///
/// Pagination is a control that displays a series of buttons that can be used to navigate to pages.
/// CurrentPage starts from 1.
/// Pagination only stores an approximate index internally.
///
[TemplatePart(PART_PreviousButton, typeof(PaginationButton))]
[TemplatePart(PART_NextButton, typeof(PaginationButton))]
[TemplatePart(PART_ButtonPanel, typeof(StackPanel))]
[TemplatePart(PART_QuickJumpInput, typeof(NumericIntUpDown))]
public class Pagination: TemplatedControl
{
public const string PART_PreviousButton = "PART_PreviousButton";
public const string PART_NextButton = "PART_NextButton";
public const string PART_ButtonPanel = "PART_ButtonPanel";
public const string PART_QuickJumpInput = "PART_QuickJumpInput";
private PaginationButton? _previousButton;
private PaginationButton? _nextButton;
private StackPanel? _buttonPanel;
private readonly PaginationButton[] _buttons = new PaginationButton[7];
private NumericIntUpDown? _quickJumpInput;
public static readonly StyledProperty CurrentPageProperty = AvaloniaProperty.Register(
nameof(CurrentPage));
public int? CurrentPage
{
get => GetValue(CurrentPageProperty);
set => SetValue(CurrentPageProperty, value);
}
private void OnCurrentPageChanged(AvaloniaPropertyChangedEventArgs args)
{
int? oldValue = args.GetOldValue();
int? newValue = args.GetNewValue();
var e = new ValueChangedEventArgs(CurrentPageChangedEvent, oldValue, newValue);
RaiseEvent(e);
}
public static readonly RoutedEvent> CurrentPageChangedEvent =
RoutedEvent.Register>(nameof(CurrentPageChanged), RoutingStrategies.Bubble);
///
/// Raised when the changes.
///
public event EventHandler>? CurrentPageChanged
{
add => AddHandler(CurrentPageChangedEvent, value);
remove => RemoveHandler(CurrentPageChangedEvent, value);
}
public static readonly StyledProperty CommandProperty = AvaloniaProperty.Register(
nameof(Command));
public ICommand? Command
{
get => GetValue(CommandProperty);
set => SetValue(CommandProperty, value);
}
public static readonly StyledProperty