feat: add CurrentPage coercion.
This commit is contained in:
@@ -33,13 +33,23 @@ public class Pagination: TemplatedControl
|
|||||||
private NumericIntUpDown? _quickJumpInput;
|
private NumericIntUpDown? _quickJumpInput;
|
||||||
|
|
||||||
public static readonly StyledProperty<int?> CurrentPageProperty = AvaloniaProperty.Register<Pagination, int?>(
|
public static readonly StyledProperty<int?> CurrentPageProperty = AvaloniaProperty.Register<Pagination, int?>(
|
||||||
nameof(CurrentPage));
|
nameof(CurrentPage) , coerce: CoerceCurrentPage);
|
||||||
|
|
||||||
public int? CurrentPage
|
public int? CurrentPage
|
||||||
{
|
{
|
||||||
get => GetValue(CurrentPageProperty);
|
get => GetValue(CurrentPageProperty);
|
||||||
set => SetValue(CurrentPageProperty, value);
|
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)
|
private void OnCurrentPageChanged(AvaloniaPropertyChangedEventArgs<int?> args)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user