diff --git a/demo/Ursa.Demo/Pages/PaginationDemo.axaml b/demo/Ursa.Demo/Pages/PaginationDemo.axaml
index 0037750..602c2da 100644
--- a/demo/Ursa.Demo/Pages/PaginationDemo.axaml
+++ b/demo/Ursa.Demo/Pages/PaginationDemo.axaml
@@ -13,11 +13,16 @@
-
+
+
+
+
+
diff --git a/demo/Ursa.Demo/ViewModels/MenuViewModel.cs b/demo/Ursa.Demo/ViewModels/MenuViewModel.cs
index aed7270..3c0765a 100644
--- a/demo/Ursa.Demo/ViewModels/MenuViewModel.cs
+++ b/demo/Ursa.Demo/ViewModels/MenuViewModel.cs
@@ -34,7 +34,7 @@ public class MenuViewModel: ViewModelBase
// new() { MenuHeader = "Number Displayer", Key = MenuKeys.MenuKeyNumberDisplayer, Status = "New" },
new() { MenuHeader = "Numeric UpDown", Key = MenuKeys.MenuKeyNumericUpDown },
new() { MenuHeader = "NumPad", Key = MenuKeys.MenuKeyNumPad, Status = "New" },
- new() { MenuHeader = "Pagination", Key = MenuKeys.MenuKeyPagination },
+ new() { MenuHeader = "Pagination", Key = MenuKeys.MenuKeyPagination, Status = "Updated" },
new() { MenuHeader = "RangeSlider", Key = MenuKeys.MenuKeyRangeSlider },
new() { MenuHeader = "Scroll To", Key = MenuKeys.MenuKeyScrollToButton, Status = "New" },
new() { MenuHeader = "Selection List", Key = MenuKeys.MenuKeySelectionList, Status = "New" },
diff --git a/src/Ursa.Themes.Semi/Controls/Pagination.axaml b/src/Ursa.Themes.Semi/Controls/Pagination.axaml
index 6406a93..8b1446d 100644
--- a/src/Ursa.Themes.Semi/Controls/Pagination.axaml
+++ b/src/Ursa.Themes.Semi/Controls/Pagination.axaml
@@ -27,8 +27,18 @@
Data="{DynamicResource PaginationForwardGlyph}"
Foreground="{DynamicResource PaginationButtonIconForeground}" />
+
+
+
+
+
Yes
No
Close
+ Jump to page
+
diff --git a/src/Ursa.Themes.Semi/Locale/zh-cn.axaml b/src/Ursa.Themes.Semi/Locale/zh-cn.axaml
index c738313..d9a2c2b 100644
--- a/src/Ursa.Themes.Semi/Locale/zh-cn.axaml
+++ b/src/Ursa.Themes.Semi/Locale/zh-cn.axaml
@@ -10,4 +10,6 @@
是
否
关闭
+ 跳至
+ 页
diff --git a/src/Ursa/Controls/Pagination/Pagination.cs b/src/Ursa/Controls/Pagination/Pagination.cs
index a13a50d..a5bde53 100644
--- a/src/Ursa/Controls/Pagination/Pagination.cs
+++ b/src/Ursa/Controls/Pagination/Pagination.cs
@@ -3,9 +3,9 @@ using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
+using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Styling;
-using Avalonia.Utilities;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
@@ -18,18 +18,18 @@ namespace Ursa.Controls;
[TemplatePart(PART_PreviousButton, typeof(PaginationButton))]
[TemplatePart(PART_NextButton, typeof(PaginationButton))]
[TemplatePart(PART_ButtonPanel, typeof(StackPanel))]
-[TemplatePart(PART_SizeChangerComboBox, typeof(ComboBox))]
+[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_SizeChangerComboBox = "PART_SizeChangerComboBox";
+ public const string PART_QuickJumpInput = "PART_QuickJumpInput";
private PaginationButton? _previousButton;
private PaginationButton? _nextButton;
private StackPanel? _buttonPanel;
private readonly PaginationButton[] _buttons = new PaginationButton[7];
- private ComboBox? _sizeChangerComboBox;
+ private NumericIntUpDown? _quickJumpInput;
public static readonly StyledProperty CurrentPageProperty = AvaloniaProperty.Register(
nameof(CurrentPage));
@@ -107,10 +107,7 @@ public class Pagination: TemplatedControl
public static readonly StyledProperty ShowQuickJumpProperty = AvaloniaProperty.Register(
nameof(ShowQuickJump));
-
- ///
- /// This feature is not implemented yet.
- ///
+
public bool ShowQuickJump
{
get => GetValue(ShowQuickJumpProperty);
@@ -145,16 +142,46 @@ public class Pagination: TemplatedControl
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
+
Button.ClickEvent.AddHandler(OnButtonClick, _previousButton, _nextButton);
_previousButton = e.NameScope.Find(PART_PreviousButton);
_nextButton = e.NameScope.Find(PART_NextButton);
_buttonPanel = e.NameScope.Find(PART_ButtonPanel);
- _sizeChangerComboBox = e.NameScope.Find(PART_SizeChangerComboBox);
Button.ClickEvent.AddHandler(OnButtonClick, _previousButton, _nextButton);
+
+ KeyDownEvent.RemoveHandler(OnQuickJumpInputKeyDown, _quickJumpInput);
+ LostFocusEvent.RemoveHandler(OnQuickJumpInputLostFocus, _quickJumpInput);
+ _quickJumpInput = e.NameScope.Find(PART_QuickJumpInput);
+ KeyDownEvent.AddHandler(OnQuickJumpInputKeyDown, _quickJumpInput);
+ LostFocusEvent.AddHandler(OnQuickJumpInputLostFocus, _quickJumpInput);
+
InitializePanelButtons();
UpdateButtonsByCurrentPage(0);
}
+ private void OnQuickJumpInputKeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.Key is Key.Enter or Key.Return)
+ {
+ SyncQuickJumperValue();
+ }
+ }
+
+ private void OnQuickJumpInputLostFocus(object sender, RoutedEventArgs e)
+ {
+ SyncQuickJumperValue();
+ }
+
+ private void SyncQuickJumperValue()
+ {
+ if (_quickJumpInput is null) return;
+ var value = _quickJumpInput?.Value;
+ if (value is null) return;
+ value = Clamp(value.Value, 1, PageCount);
+ SetCurrentValue(CurrentPageProperty, value);
+ _quickJumpInput?.SetCurrentValue(NumericIntUpDown.ValueProperty, null);
+ }
+
private void OnButtonClick(object? sender, RoutedEventArgs e)
{
var diff = Equals(sender, _previousButton) ? -1 : 1;