feat: Add Pagination control, style and demo.
This commit is contained in:
1 parent
2c91527181
commit
7da3acceb1
6 files changed
+611
No files matched your search
@@ -58,6 +58,7 @@
|
||||
[ "UniformSpacingPanel", "UniformSpacingPanelDemo", "Brush.IncreaseHorizontalSpacing", "", "Layout" ],
|
||||
[ "ProgressBar", "ProgressBarDemo", "Brush.ProgressBar", "", "Feedback" ],
|
||||
[ "Rate", "RateDemo", "Brush.Favorite", "", "Feedback" ],
|
||||
[ "Pagination", "PaginationDemo", "Brush.Paginator", "", "Navigation" ],
|
||||
[ "Loading", "LoadingDemo", "Brush.Loading", "", "Feedback" ],
|
||||
[ "Tag", "TagDemo", "Brush.Tag", "", "DataDisplay" ],
|
||||
[ "Badge", "BadgeDemo", "Brush.CheckDot", "", "DataDisplay" ],
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
x:Class="HandyControlDemo.UserControl.PaginationDemo"
|
||||
Background="{DynamicResource RegionBrush}">
|
||||
<TransitioningContentControl>
|
||||
<Grid Margin="32"
|
||||
RowDefinitions="Auto,*">
|
||||
<hc:Pagination x:Name="PaginationCtl"
|
||||
MaxPageCount="10"
|
||||
DataCountPerPage="10"
|
||||
PageIndex="1"
|
||||
IsJumpEnabled="True"
|
||||
PageUpdated="Pagination_OnPageUpdated" />
|
||||
|
||||
<Border Grid.Row="1"
|
||||
MaxWidth="600"
|
||||
Margin="0,16,0,0"
|
||||
Padding="12"
|
||||
BorderBrush="{DynamicResource BorderBrush}"
|
||||
Background="{DynamicResource RegionBrush}">
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<TextBlock Text="Current Page Data"
|
||||
FontWeight="Bold"
|
||||
Margin="0,0,0,8" />
|
||||
<ListBox Grid.Row="1"
|
||||
ItemsSource="{Binding DataList}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid ColumnDefinitions="60,160,90,*"
|
||||
Margin="0,4">
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="{Binding Index}" />
|
||||
<TextBlock Grid.Column="1"
|
||||
Text="{Binding Name}" />
|
||||
<TextBlock Grid.Column="2"
|
||||
Text="{Binding Type}" />
|
||||
<TextBlock Grid.Column="3"
|
||||
Text="{Binding Remark}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</TransitioningContentControl>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using HandyControl.Data;
|
||||
using HandyControlDemo.Data;
|
||||
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class PaginationDemo : Avalonia.Controls.UserControl
|
||||
{
|
||||
private readonly List<DemoDataModel> _totalDataList;
|
||||
|
||||
public static readonly DirectProperty<PaginationDemo, ObservableCollection<DemoDataModel>> DataListProperty =
|
||||
AvaloniaProperty.RegisterDirect<PaginationDemo, ObservableCollection<DemoDataModel>>(nameof(DataList), o => o.DataList);
|
||||
|
||||
public PaginationDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = this;
|
||||
|
||||
_totalDataList = BuildDataList(100);
|
||||
DataList = new ObservableCollection<DemoDataModel>();
|
||||
LoadPage(1, 10);
|
||||
}
|
||||
|
||||
public ObservableCollection<DemoDataModel> DataList { get; }
|
||||
|
||||
private void Pagination_OnPageUpdated(object? sender, FunctionEventArgs<int> e)
|
||||
{
|
||||
var page = Math.Max(e.Info, 1);
|
||||
LoadPage(page, 10);
|
||||
}
|
||||
|
||||
private void LoadPage(int page, int pageSize)
|
||||
{
|
||||
DataList.Clear();
|
||||
foreach (var item in _totalDataList.Skip((page - 1) * pageSize).Take(pageSize))
|
||||
{
|
||||
DataList.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<DemoDataModel> BuildDataList(int total)
|
||||
{
|
||||
var list = new List<DemoDataModel>();
|
||||
for (var i = 1; i <= total; i++)
|
||||
{
|
||||
list.Add(new DemoDataModel
|
||||
{
|
||||
Index = i,
|
||||
Name = $"Name{i}",
|
||||
IsSelected = i % 2 == 0,
|
||||
Type = (DemoType)(i % 6 + 1),
|
||||
ImgPath = string.Empty,
|
||||
Remark = new string((i % 10).ToString()[0], 10)
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user