feat: add CurrentPage coercion.
This commit is contained in:
@@ -33,7 +33,7 @@ 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
|
||||||
{
|
{
|
||||||
@@ -41,6 +41,16 @@ public class Pagination: TemplatedControl
|
|||||||
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)
|
||||||
{
|
{
|
||||||
int? oldValue = args.GetOldValue<int?>();
|
int? oldValue = args.GetOldValue<int?>();
|
||||||
|
|||||||
Reference in New Issue
Block a user