fix: make sure page count is properly calculated even if template is not loaded.
This commit is contained in:
@@ -30,7 +30,8 @@
|
|||||||
TotalCount="600" />
|
TotalCount="600" />
|
||||||
|
|
||||||
<TextBlock Text="Tiny Pagination"/>
|
<TextBlock Text="Tiny Pagination"/>
|
||||||
<u:Pagination Theme="{DynamicResource TinyPagination}" TotalCount="100" PageSize="1"/>
|
<u:Pagination Theme="{DynamicResource TinyPagination}" Command="{Binding LoadPageCommand}"
|
||||||
|
CommandParameter="{Binding $self.CurrentPage}" PageSize="1" TotalCount="100" />
|
||||||
<u:Pagination Classes="ReadOnly" Theme="{DynamicResource TinyPagination}" TotalCount="100" PageSize="1"/>
|
<u:Pagination Classes="ReadOnly" Theme="{DynamicResource TinyPagination}" TotalCount="100" PageSize="1"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -114,8 +114,9 @@ public class Pagination: TemplatedControl
|
|||||||
|
|
||||||
private int _pageCount;
|
private int _pageCount;
|
||||||
|
|
||||||
public static readonly DirectProperty<Pagination, int> PageCountProperty = AvaloniaProperty.RegisterDirect<Pagination, int>(
|
public static readonly DirectProperty<Pagination, int> PageCountProperty =
|
||||||
nameof(PageCount), o => o.PageCount);
|
AvaloniaProperty.RegisterDirect<Pagination, int>(
|
||||||
|
nameof(PageCount), o => o.PageCount, (o, e) => o.PageCount = e);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Page count.
|
/// Page count.
|
||||||
@@ -291,11 +292,14 @@ public class Pagination: TemplatedControl
|
|||||||
/// <param name="page"></param>
|
/// <param name="page"></param>
|
||||||
private void UpdateButtonsByCurrentPage(int? page)
|
private void UpdateButtonsByCurrentPage(int? page)
|
||||||
{
|
{
|
||||||
if (_buttonPanel is null) return;
|
|
||||||
if (PageSize == 0) return;
|
if (PageSize == 0) return;
|
||||||
|
|
||||||
int? currentPage = CurrentPage;
|
|
||||||
int pageCount = TotalCount / PageSize;
|
int pageCount = TotalCount / PageSize;
|
||||||
|
if (_buttonPanel is null)
|
||||||
|
{
|
||||||
|
SetCurrentValue(PageCountProperty, pageCount);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int? currentPage = CurrentPage;
|
||||||
int residue = TotalCount % PageSize;
|
int residue = TotalCount % PageSize;
|
||||||
if (residue > 0)
|
if (residue > 0)
|
||||||
{
|
{
|
||||||
@@ -360,7 +364,7 @@ public class Pagination: TemplatedControl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PageCount = pageCount;
|
SetCurrentValue(PageCountProperty, pageCount);
|
||||||
SetCurrentValue(CurrentPageProperty, currentPage);
|
SetCurrentValue(CurrentPageProperty, currentPage);
|
||||||
if (_previousButton != null) _previousButton.IsEnabled = (CurrentPage ?? int.MaxValue) > 1;
|
if (_previousButton != null) _previousButton.IsEnabled = (CurrentPage ?? int.MaxValue) > 1;
|
||||||
if (_nextButton != null) _nextButton.IsEnabled = (CurrentPage ?? 0) < PageCount;
|
if (_nextButton != null) _nextButton.IsEnabled = (CurrentPage ?? 0) < PageCount;
|
||||||
|
|||||||
Reference in New Issue
Block a user