feat: add ExpandButton
This commit is contained in:
@@ -19,4 +19,20 @@
|
|||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter>
|
</Setter>
|
||||||
</ControlTheme>
|
</ControlTheme>
|
||||||
|
|
||||||
|
<ControlTheme x:Key="{x:Type u:PaginationExpandButton}" TargetType="u:PaginationExpandButton">
|
||||||
|
<Setter Property="Template">
|
||||||
|
<ControlTemplate TargetType="u:PaginationExpandButton">
|
||||||
|
<Grid>
|
||||||
|
<Button Name="button" Content="..." />
|
||||||
|
<Popup
|
||||||
|
IsLightDismissEnabled="True"
|
||||||
|
IsOpen="{Binding #button.IsPointerOver}"
|
||||||
|
PlacementTarget="button">
|
||||||
|
<ListBox Background="White" ItemsSource="{TemplateBinding Pages}" />
|
||||||
|
</Popup>
|
||||||
|
</Grid>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter>
|
||||||
|
</ControlTheme>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
|
|||||||
@@ -23,6 +23,12 @@ public class Pagination: TemplatedControl
|
|||||||
private StackPanel? _buttonPanel;
|
private StackPanel? _buttonPanel;
|
||||||
private ComboBox? _sizeChangerComboBox;
|
private ComboBox? _sizeChangerComboBox;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// To reduce allocation, there are maximum of 7 buttons and 2 selection controls. it will be reused.
|
||||||
|
/// </summary>
|
||||||
|
private PaginationExpandButton? _leftSelection;
|
||||||
|
private PaginationExpandButton? _rightSelection;
|
||||||
|
|
||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
@@ -34,6 +40,8 @@ public class Pagination: TemplatedControl
|
|||||||
_sizeChangerComboBox = e.NameScope.Find<ComboBox>(PART_SizeChangerComboBox);
|
_sizeChangerComboBox = e.NameScope.Find<ComboBox>(PART_SizeChangerComboBox);
|
||||||
if (_previousButton != null) _previousButton.Click += OnButtonClick;
|
if (_previousButton != null) _previousButton.Click += OnButtonClick;
|
||||||
if (_nextButton != null) _nextButton.Click += OnButtonClick;
|
if (_nextButton != null) _nextButton.Click += OnButtonClick;
|
||||||
|
_leftSelection = new PaginationExpandButton();
|
||||||
|
_rightSelection = new PaginationExpandButton();
|
||||||
UpdateButtons();
|
UpdateButtons();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -60,7 +68,7 @@ public class Pagination: TemplatedControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<int> PageSizeProperty = AvaloniaProperty.Register<Pagination, int>(
|
public static readonly StyledProperty<int> PageSizeProperty = AvaloniaProperty.Register<Pagination, int>(
|
||||||
nameof(PageSize), defaultValue: 100);
|
nameof(PageSize), defaultValue: 50);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Page size.
|
/// Page size.
|
||||||
@@ -147,7 +155,15 @@ public class Pagination: TemplatedControl
|
|||||||
_buttonPanel?.Children.Clear();
|
_buttonPanel?.Children.Clear();
|
||||||
for (int i = 0; i < pageCount; i++)
|
for (int i = 0; i < pageCount; i++)
|
||||||
{
|
{
|
||||||
_buttonPanel?.Children.Add(new Button { Content = i + 1 });
|
if (i == 1 && _leftSelection is not null)
|
||||||
|
{
|
||||||
|
_leftSelection.Pages = new AvaloniaList<int>() { PageSize + 1, PageSize + 2, PageSize + 3 };
|
||||||
|
_buttonPanel?.Children.Add(_leftSelection);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_buttonPanel?.Children.Add(new Button { Content = i + 1 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
19
src/Ursa/Controls/Pagination/PaginationExpandButton.cs
Normal file
19
src/Ursa/Controls/Pagination/PaginationExpandButton.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Collections;
|
||||||
|
using Avalonia.Controls.Primitives;
|
||||||
|
|
||||||
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
|
public class PaginationExpandButton: TemplatedControl
|
||||||
|
{
|
||||||
|
public static readonly StyledProperty<AvaloniaList<int>> PagesProperty = AvaloniaProperty.Register<PaginationExpandButton, AvaloniaList<int>>(
|
||||||
|
nameof(Pages));
|
||||||
|
|
||||||
|
public AvaloniaList<int> Pages
|
||||||
|
{
|
||||||
|
get => GetValue(PagesProperty);
|
||||||
|
set => SetValue(PagesProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user