feat: add CurrentPage coercion.

This commit is contained in:
rabbitism
2024-08-10 00:17:36 +08:00
parent 1a99b92eee
commit b0c86e91a1

View File

@@ -33,13 +33,23 @@ public class Pagination: TemplatedControl
private NumericIntUpDown? _quickJumpInput;
public static readonly StyledProperty<int?> CurrentPageProperty = AvaloniaProperty.Register<Pagination, int?>(
nameof(CurrentPage));
nameof(CurrentPage) , coerce: CoerceCurrentPage);
public int? CurrentPage
{
get => GetValue(CurrentPageProperty);
set => SetValue(CurrentPageProperty, value);
}
private static int? CoerceCurrentPage(AvaloniaObject arg1, int? arg2)
{
if (arg2 is null) return null;
if (arg1 is Pagination p)
{
arg2 = MathHelpers.SafeClamp(arg2.Value, 1, p.PageCount + 1);
}
return arg2;
}
private void OnCurrentPageChanged(AvaloniaPropertyChangedEventArgs<int?> args)
{