mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-28 14:20:47 +08:00
Add IsHideOnSinglePage support for Pagination
This commit is contained in:
@@ -4,6 +4,7 @@ using AtomUI.Theme.Utils;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
@@ -17,6 +18,9 @@ public abstract class AbstractPagination : TemplatedControl,
|
||||
|
||||
#region 公共属性定义
|
||||
|
||||
public static readonly StyledProperty<bool> IsHideOnSinglePageProperty =
|
||||
AvaloniaProperty.Register<AbstractPagination, bool>(nameof(IsHideOnSinglePage));
|
||||
|
||||
public static readonly StyledProperty<PaginationAlign> AlignProperty =
|
||||
AvaloniaProperty.Register<AbstractPagination, PaginationAlign>(nameof(PaginationAlign));
|
||||
|
||||
@@ -37,6 +41,17 @@ public abstract class AbstractPagination : TemplatedControl,
|
||||
public static readonly StyledProperty<bool> IsMotionEnabledProperty =
|
||||
MotionAwareControlProperty.IsMotionEnabledProperty.AddOwner<AbstractPagination>();
|
||||
|
||||
public static readonly DirectProperty<AbstractPagination, int> PageCountProperty =
|
||||
AvaloniaProperty.RegisterDirect<AbstractPagination, int>(nameof(PageCount),
|
||||
o => o.PageCount,
|
||||
(o, v) => o.PageCount = v);
|
||||
|
||||
public bool IsHideOnSinglePage
|
||||
{
|
||||
get => GetValue(IsHideOnSinglePageProperty);
|
||||
set => SetValue(IsHideOnSinglePageProperty, value);
|
||||
}
|
||||
|
||||
public PaginationAlign Align
|
||||
{
|
||||
get => GetValue(AlignProperty);
|
||||
@@ -73,6 +88,14 @@ public abstract class AbstractPagination : TemplatedControl,
|
||||
set => SetValue(IsMotionEnabledProperty, value);
|
||||
}
|
||||
|
||||
private int _pageCount;
|
||||
|
||||
public int PageCount
|
||||
{
|
||||
get => _pageCount;
|
||||
internal set => SetAndRaise(PageCountProperty, ref _pageCount, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 公共事件定义
|
||||
@@ -122,6 +145,19 @@ public abstract class AbstractPagination : TemplatedControl,
|
||||
HandlePageConditionChanged();
|
||||
}
|
||||
}
|
||||
|
||||
if (change.Property == IsHideOnSinglePageProperty ||
|
||||
change.Property == PageCountProperty)
|
||||
{
|
||||
if (IsHideOnSinglePage)
|
||||
{
|
||||
SetValue(IsVisibleProperty, PageCount > 1, BindingPriority.Template);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetValue(IsVisibleProperty, true, BindingPriority.Template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void HandlePageConditionChanged()
|
||||
@@ -131,6 +167,7 @@ public abstract class AbstractPagination : TemplatedControl,
|
||||
var pageCount = (int)Math.Ceiling(total / (double)pageSize);
|
||||
var currentPage = Math.Max(1, Math.Min(CurrentPage, pageCount));
|
||||
CurrentPage = currentPage;
|
||||
PageCount = pageCount;
|
||||
NotifyPageConditionChanged(currentPage, pageCount, pageSize, total);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,6 @@ public class Pagination : AbstractPagination, IControlSharedTokenResourcesHost
|
||||
|
||||
#region 公共属性定义
|
||||
|
||||
public static readonly StyledProperty<bool> IsHideOnSinglePageProperty =
|
||||
AvaloniaProperty.Register<Pagination, bool>(nameof(IsHideOnSinglePage));
|
||||
|
||||
public static readonly StyledProperty<bool> IsShowSizeChangerProperty =
|
||||
AvaloniaProperty.Register<Pagination, bool>(nameof(IsShowSizeChanger));
|
||||
|
||||
@@ -42,12 +39,6 @@ public class Pagination : AbstractPagination, IControlSharedTokenResourcesHost
|
||||
public static readonly StyledProperty<string?> TotalInfoTemplateProperty =
|
||||
AvaloniaProperty.Register<Pagination, string?>(nameof(TotalInfoTemplate));
|
||||
|
||||
public bool IsHideOnSinglePage
|
||||
{
|
||||
get => GetValue(IsHideOnSinglePageProperty);
|
||||
set => SetValue(IsHideOnSinglePageProperty, value);
|
||||
}
|
||||
|
||||
public bool IsShowSizeChanger
|
||||
{
|
||||
get => GetValue(IsShowSizeChangerProperty);
|
||||
|
||||
Reference in New Issue
Block a user