Files
ShrlAlgoToolkit/NeuWPF/NeoUI/Controls/PaginationControl.xaml
ShrlAlgo 955a01f564 整理
2025-08-20 12:10:35 +08:00

150 lines
8.3 KiB
XML

<!-- 文件路径: /Themes/Generic.xaml -->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:conv="clr-namespace:NeoUI.Converters"
xmlns:local="clr-namespace:NeoUI.Controls"
xmlns:nvd="clr-namespace:NeoUI.Controls.Decorations"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/NeuWPF;component/Controls/ButtonsStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>-->
<!-- 页码按钮的样式 -->
<Style TargetType="Button" x:Key="PaginationButtonStyle">
<Setter Property="MinWidth" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="Margin" Value="2,0" />
<Setter Property="Background" Value="{DynamicResource BackgroundContainerBrush}" />
<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>
<nvd:EmbossBorder
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Foreground="{TemplateBinding Foreground}"
Intensity="0.4"
x:Name="emboss" />
<nvd:SlotBorder
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Foreground="{TemplateBinding Foreground}"
Intensity=".4"
Visibility="Collapsed"
x:Name="slot" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{x:Static conv:ComparisionConverter.Instance}">
<Binding Path="Value" />
<!-- 来自按钮的 DataContext (PageItem.Value) -->
<Binding Path="CurrentPage" RelativeSource="{RelativeSource AncestorType=local:PaginationControl}" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Visibility" TargetName="emboss" Value="Collapsed" />
<Setter Property="Visibility" TargetName="slot" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- 核心: 当按钮的值等于控件的当前页时,改变样式 -->
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{x:Static conv:ComparisionConverter.Instance}">
<Binding Path="Value" />
<!-- 来自按钮的 DataContext (PageItem.Value) -->
<Binding Path="CurrentPage" RelativeSource="{RelativeSource AncestorType=local:PaginationControl}" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
<!--<Setter Property="Foreground" Value="{DynamicResource TextOnAccentPrimaryBrush}" />-->
<!--<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>
<!-- PaginationControl 的主模板 -->
<Style TargetType="{x:Type local:PaginationControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:PaginationControl}">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<!-- 页码按钮列表 -->
<ItemsControl ItemsSource="{Binding PageItems, RelativeSource={RelativeSource TemplatedParent}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type local:PageItem}">
<Button
Content="{Binding Text}"
IsEnabled="{Binding IsEnabled}"
Style="{StaticResource PaginationButtonStyle}"
ToolTip="{Binding ToolTip}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- 页面尺寸选择器 -->
<ComboBox
Height="32"
ItemsSource="{Binding PageSizeOptions, RelativeSource={RelativeSource TemplatedParent}}"
Margin="8,0,0,0"
SelectedItem="{Binding PageSize, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
VerticalContentAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding StringFormat={}{0} 条/页}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- 跳转输入框 -->
<StackPanel
Margin="8,0,0,0"
Orientation="Horizontal"
VerticalAlignment="Center"
Visibility="{Binding ShowPageInput, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static conv:BooleanToVisibilityConverter.CollapsedInstance}}">
<TextBlock Text="跳至" VerticalAlignment="Center" />
<TextBox
HorizontalContentAlignment="Center"
Margin="4,0"
Text="{Binding CurrentPage, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
VerticalContentAlignment="Center"
Width="50"
x:Name="PART_PageInputTextBox" />
<TextBlock Text="页" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>