fix: fix page initialization issue.

This commit is contained in:
Dong Bin
2025-02-20 22:16:25 +08:00
parent 27740b578a
commit c672b5bef3
2 changed files with 3 additions and 0 deletions

View File

@@ -166,6 +166,7 @@ public class Pagination : TemplatedControl
private static int? CoerceCurrentPage(AvaloniaObject arg1, int? arg2)
{
if (arg2 is null) return null;
// Only coerce the value if the pagination is initialized. Otherwise the value will be coerced to default because PageCount is not yet determined.
if (arg1 is Pagination { IsInitialized: true } p)
{
arg2 = MathHelpers.SafeClamp(arg2.Value, 1, p.PageCount);
@@ -221,6 +222,7 @@ public class Pagination : TemplatedControl
LostFocusEvent.AddHandler(OnQuickJumpInputLostFocus, _quickJumpInput);
InitializePanelButtons();
CurrentPage = MathHelpers.SafeClamp(CurrentPage ?? 1, 1, PageCount);
UpdateButtonsByCurrentPage(CurrentPage);
}