Files
ShrlAlgoToolkit/Melskin/Controls/Pagination.xaml

273 lines
15 KiB
Plaintext
Raw Normal View History

2025-08-20 12:10:35 +08:00
<!-- 文件路径: /Themes/Generic.xaml -->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2026-02-20 15:31:44 +08:00
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
2026-01-02 17:30:41 +08:00
xmlns:controls="clr-namespace:Melskin.Controls"
xmlns:converters="clr-namespace:Melskin.Converters"
2026-02-20 15:31:44 +08:00
xmlns:decorations="clr-namespace:Melskin.Controls.Decorations">
2025-08-20 12:10:35 +08:00
2025-12-28 11:47:54 +08:00
<ResourceDictionary.MergedDictionaries>
2026-01-02 17:30:41 +08:00
<ResourceDictionary Source="/Melskin;component/Controls/ComboBox.xaml" />
<ResourceDictionary Source="/Melskin;component/Controls/TextBox.xaml" />
2025-12-28 11:47:54 +08:00
</ResourceDictionary.MergedDictionaries>
2025-08-20 12:10:35 +08:00
<!-- 页码按钮的样式 -->
2026-02-20 15:31:44 +08:00
<Style x:Key="EmbossPaginationButtonStyle" TargetType="Button">
2025-08-20 12:10:35 +08:00
<Setter Property="MinWidth" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="Margin" Value="2,0" />
2025-08-26 21:33:20 +08:00
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
2025-08-20 12:10:35 +08:00
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Focusable" Value="False" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
2025-09-04 22:39:00 +08:00
<decorations:EmbossBorder
2026-02-20 15:31:44 +08:00
x:Name="emboss"
2025-08-20 12:10:35 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Foreground="{TemplateBinding Foreground}"
2026-02-20 15:31:44 +08:00
Intensity="0.4" />
2025-09-04 22:39:00 +08:00
<decorations:SlotBorder
2026-02-20 15:31:44 +08:00
x:Name="slot"
2025-08-20 12:10:35 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Foreground="{TemplateBinding Foreground}"
Intensity=".4"
2026-02-20 15:31:44 +08:00
Visibility="Collapsed" />
2025-08-20 12:10:35 +08:00
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding>
2025-09-04 22:39:00 +08:00
<MultiBinding Converter="{x:Static converters:ComparisionConverter.Instance}">
2025-08-20 12:10:35 +08:00
<Binding Path="Value" />
<!-- 来自按钮的 DataContext (PageItem.Value) -->
2025-10-10 11:19:58 +08:00
<Binding Path="CurrentPage" RelativeSource="{RelativeSource AncestorType=controls:Pagination}" />
2025-08-20 12:10:35 +08:00
</MultiBinding>
</DataTrigger.Binding>
2026-02-20 15:31:44 +08:00
<Setter TargetName="emboss" Property="Visibility" Value="Collapsed" />
<Setter TargetName="slot" Property="Visibility" Value="Visible" />
2025-08-20 12:10:35 +08:00
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- 核心: 当按钮的值等于控件的当前页时,改变样式 -->
<DataTrigger Value="True">
<DataTrigger.Binding>
2025-09-04 22:39:00 +08:00
<MultiBinding Converter="{x:Static converters:ComparisionConverter.Instance}">
2025-08-20 12:10:35 +08:00
<Binding Path="Value" />
<!-- 来自按钮的 DataContext (PageItem.Value) -->
2025-10-10 11:19:58 +08:00
<Binding Path="CurrentPage" RelativeSource="{RelativeSource AncestorType=controls:Pagination}" />
2025-08-20 12:10:35 +08:00
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
2025-09-12 09:55:36 +08:00
<!--<Setter Property="Foreground" Value="{DynamicResource TextAccentBrush}" />-->
2025-08-20 12:10:35 +08:00
<!--<Setter Property="Background" Value="{DynamicResource PrimaryNormalBrush}" />-->
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.6" />
<Setter Property="Cursor" Value="No" />
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
</Trigger>
</Style.Triggers>
</Style>
2026-02-20 15:31:44 +08:00
<Style x:Key="PaginationButtonStyle" TargetType="Button">
2025-12-23 21:35:54 +08:00
<Setter Property="MinWidth" Value="34" />
<Setter Property="MinHeight" Value="34" />
<Setter Property="Margin" Value="2,0" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Focusable" Value="False" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Border
2026-02-20 15:31:44 +08:00
x:Name="Border"
2025-12-23 21:35:54 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
2026-02-20 15:31:44 +08:00
CornerRadius="4" />
2025-12-23 21:35:54 +08:00
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<!-- 核心: 当按钮的值等于控件的当前页时,改变样式 -->
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{x:Static converters:ComparisionConverter.Instance}">
<!-- 来自按钮的 DataContext (PageItem.Value) -->
<Binding Path="Value" />
<Binding Path="CurrentPage" RelativeSource="{RelativeSource AncestorType=controls:Pagination}" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
2026-02-20 15:31:44 +08:00
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
2025-12-23 21:35:54 +08:00
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{x:Static converters:ComparisionConverter.Instance}">
<Binding Path="Value" />
<Binding Path="CurrentPage" RelativeSource="{RelativeSource AncestorType=controls:Pagination}" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.6" />
<Setter Property="Cursor" Value="No" />
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
</Trigger>
</Style.Triggers>
</Style>
2025-08-20 12:10:35 +08:00
<!-- PaginationControl 的主模板 -->
2026-02-20 15:31:44 +08:00
<Style x:Key="EmbossPaginationStyle" TargetType="{x:Type controls:Pagination}">
2025-12-28 11:47:54 +08:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:Pagination}">
2026-02-20 15:31:44 +08:00
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
2025-12-28 11:47:54 +08:00
<!-- 页码按钮列表 -->
<ItemsControl ItemsSource="{Binding PageItems, RelativeSource={RelativeSource TemplatedParent}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type controls:PageItem}">
<Button
Content="{Binding Text}"
IsEnabled="{Binding IsEnabled}"
Style="{StaticResource EmbossPaginationButtonStyle}"
ToolTip="{Binding ToolTip}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- 页面尺寸选择器 -->
<ComboBox
2026-01-02 17:30:30 +08:00
Margin="8,0,0,0"
2026-02-20 15:31:44 +08:00
ItemsSource="{Binding PageSizeOptions, RelativeSource={RelativeSource TemplatedParent}}"
2025-12-28 11:47:54 +08:00
SelectedItem="{Binding PageSize, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
Style="{StaticResource FloatComboBoxStyle}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding StringFormat={}{0} 条/页}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- 跳转输入框 -->
<StackPanel
Margin="8,0,0,0"
2026-01-02 17:30:30 +08:00
VerticalAlignment="Center"
2026-02-20 15:31:44 +08:00
Orientation="Horizontal"
2025-12-28 11:47:54 +08:00
Visibility="{Binding ShowPageInput, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:BooleanToVisibilityConverter.CollapsedInstance}}">
2026-02-20 15:31:44 +08:00
<TextBlock VerticalAlignment="Center" Text="跳至" />
2025-12-28 11:47:54 +08:00
<TextBox
2026-02-20 15:31:44 +08:00
x:Name="PART_PageInputTextBox"
Width="50"
2026-01-02 17:30:30 +08:00
Margin="4,0"
2026-02-20 15:31:44 +08:00
HorizontalContentAlignment="Center"
2025-12-28 11:47:54 +08:00
Style="{StaticResource SlotTextBoxStyle}"
2026-02-20 15:31:44 +08:00
Text="{Binding CurrentPage, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
<TextBlock VerticalAlignment="Center" Text="页" />
2025-12-28 11:47:54 +08:00
</StackPanel>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-10-10 11:19:58 +08:00
<Style TargetType="{x:Type controls:Pagination}">
2025-08-20 12:10:35 +08:00
<Setter Property="Template">
<Setter.Value>
2025-10-10 11:19:58 +08:00
<ControlTemplate TargetType="{x:Type controls:Pagination}">
2026-02-20 15:31:44 +08:00
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
2025-08-20 12:10:35 +08:00
<!-- 页码按钮列表 -->
<ItemsControl ItemsSource="{Binding PageItems, RelativeSource={RelativeSource TemplatedParent}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type controls:PageItem}">
2025-08-20 12:10:35 +08:00
<Button
Content="{Binding Text}"
IsEnabled="{Binding IsEnabled}"
Style="{StaticResource PaginationButtonStyle}"
ToolTip="{Binding ToolTip}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- 页面尺寸选择器 -->
<ComboBox
2026-01-02 17:30:30 +08:00
Margin="8,0,0,0"
2026-02-20 15:31:44 +08:00
VerticalContentAlignment="Center"
ItemsSource="{Binding PageSizeOptions, RelativeSource={RelativeSource TemplatedParent}}"
SelectedItem="{Binding PageSize, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
2025-08-20 12:10:35 +08:00
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding StringFormat={}{0} 条/页}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- 跳转输入框 -->
<StackPanel
Margin="8,0,0,0"
2026-01-02 17:30:30 +08:00
VerticalAlignment="Center"
2026-02-20 15:31:44 +08:00
Orientation="Horizontal"
2025-09-04 22:39:00 +08:00
Visibility="{Binding ShowPageInput, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:BooleanToVisibilityConverter.CollapsedInstance}}">
2026-02-20 15:31:44 +08:00
<TextBlock VerticalAlignment="Center" Text="跳至" />
2025-08-20 12:10:35 +08:00
<TextBox
2026-02-20 15:31:44 +08:00
x:Name="PART_PageInputTextBox"
Width="50"
2026-01-02 17:30:30 +08:00
Margin="4,0"
2026-02-20 15:31:44 +08:00
HorizontalContentAlignment="Center"
2025-08-20 12:10:35 +08:00
VerticalContentAlignment="Center"
2026-02-20 15:31:44 +08:00
Text="{Binding CurrentPage, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
<TextBlock VerticalAlignment="Center" Text="页" />
2025-08-20 12:10:35 +08:00
</StackPanel>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>