refactor: Pagination button group and content handling
Removed hardcoded GroupName and Content from PaginationButtonStyle and XAML templates. GroupName is now set programmatically with a unique value per control instance, and button content is set in code. Also fixed minor naming and parameter consistency in Pagination.cs.
This commit is contained in:
1 parent
ac67e75388
commit
b9ee91a56b
4 files changed
+19
-21
No files matched your search
@@ -13042,7 +13042,6 @@
|
|||||||
<Setter Property="MinHeight" Value="20" />
|
<Setter Property="MinHeight" Value="20" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="PaginationButtonStyle" BasedOn="{StaticResource BaseStyle}" TargetType="RadioButton">
|
<Style x:Key="PaginationButtonStyle" BasedOn="{StaticResource BaseStyle}" TargetType="RadioButton">
|
||||||
<Setter Property="GroupName" Value="1" />
|
|
||||||
<Setter Property="MinWidth" Value="30" />
|
<Setter Property="MinWidth" Value="30" />
|
||||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
||||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
|
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
|
||||||
@@ -13116,7 +13115,7 @@
|
|||||||
<interactivity:EventToCommand Command="interactivity:ControlCommands.Selected" PassEventArgsToCommand="True" />
|
<interactivity:EventToCommand Command="interactivity:ControlCommands.Selected" PassEventArgsToCommand="True" />
|
||||||
</interactivity:RoutedEventTrigger>
|
</interactivity:RoutedEventTrigger>
|
||||||
</interactivity:Interaction.Triggers>
|
</interactivity:Interaction.Triggers>
|
||||||
<RadioButton Name="PART_ButtonFirst" Content="1" IsChecked="True" Style="{TemplateBinding PaginationButtonStyle}" />
|
<RadioButton Name="PART_ButtonFirst" IsChecked="True" Style="{TemplateBinding PaginationButtonStyle}" />
|
||||||
<Border Name="PART_MoreLeft" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
<Border Name="PART_MoreLeft" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
||||||
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center" />
|
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center" />
|
||||||
</Border>
|
</Border>
|
||||||
@@ -13124,7 +13123,7 @@
|
|||||||
<Border Name="PART_MoreRight" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
<Border Name="PART_MoreRight" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
||||||
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center" />
|
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center" />
|
||||||
</Border>
|
</Border>
|
||||||
<RadioButton Name="PART_ButtonLast" Content="10" Style="{TemplateBinding PaginationButtonStyle}" />
|
<RadioButton Name="PART_ButtonLast" Style="{TemplateBinding PaginationButtonStyle}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Button x:Name="PART_ButtonRight" MinWidth="30" Padding="10,8" hc:IconElement.Geometry="{StaticResource RightGeometry}" hc:BorderElement.CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource CornerRadiusSplitConverter},ConverterParameter='0,1,1,0'}" Margin="-1,0,0,0" Command="interactivity:ControlCommands.Next" />
|
<Button x:Name="PART_ButtonRight" MinWidth="30" Padding="10,8" hc:IconElement.Geometry="{StaticResource RightGeometry}" hc:BorderElement.CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource CornerRadiusSplitConverter},ConverterParameter='0,1,1,0'}" Margin="-1,0,0,0" Command="interactivity:ControlCommands.Next" />
|
||||||
<hc:NumericUpDown x:Name="PART_Jump" IsEnabled="{TemplateBinding IsJumpEnabled}" Visibility="{TemplateBinding IsJumpEnabled,Converter={StaticResource Boolean2VisibilityConverter}}" Margin="6,0,0,0" Maximum="{Binding MaxPageCount,RelativeSource={RelativeSource TemplatedParent}}" Minimum="1" />
|
<hc:NumericUpDown x:Name="PART_Jump" IsEnabled="{TemplateBinding IsJumpEnabled}" Visibility="{TemplateBinding IsJumpEnabled,Converter={StaticResource Boolean2VisibilityConverter}}" Margin="6,0,0,0" Maximum="{Binding MaxPageCount,RelativeSource={RelativeSource TemplatedParent}}" Minimum="1" />
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ public class Pagination : Control
|
|||||||
|
|
||||||
#region Data
|
#region Data
|
||||||
|
|
||||||
|
private readonly string _groupName = Guid.NewGuid().ToString("N");
|
||||||
|
|
||||||
private Button _buttonLeft;
|
private Button _buttonLeft;
|
||||||
private Button _buttonRight;
|
private Button _buttonRight;
|
||||||
private RadioButton _buttonFirst;
|
private RadioButton _buttonFirst;
|
||||||
@@ -45,11 +47,8 @@ public class Pagination : Control
|
|||||||
private FrameworkElement _moreRight;
|
private FrameworkElement _moreRight;
|
||||||
private RadioButton _buttonLast;
|
private RadioButton _buttonLast;
|
||||||
private NumericUpDown _jumpNumericUpDown;
|
private NumericUpDown _jumpNumericUpDown;
|
||||||
|
|
||||||
private bool _appliedTemplate;
|
private bool _appliedTemplate;
|
||||||
|
|
||||||
private readonly string groupName = Guid.NewGuid().ToString("N");
|
|
||||||
|
|
||||||
#endregion Data
|
#endregion Data
|
||||||
|
|
||||||
#region Public Events
|
#region Public Events
|
||||||
@@ -93,9 +92,9 @@ public class Pagination : Control
|
|||||||
public static readonly DependencyProperty MaxPageCountProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty MaxPageCountProperty = DependencyProperty.Register(
|
||||||
nameof(MaxPageCount), typeof(int), typeof(Pagination), new PropertyMetadata(ValueBoxes.Int1Box, OnMaxPageCountChanged, CoerceMaxPageCount), ValidateHelper.IsInRangeOfPosIntIncludeZero);
|
nameof(MaxPageCount), typeof(int), typeof(Pagination), new PropertyMetadata(ValueBoxes.Int1Box, OnMaxPageCountChanged, CoerceMaxPageCount), ValidateHelper.IsInRangeOfPosIntIncludeZero);
|
||||||
|
|
||||||
private static object CoerceMaxPageCount(DependencyObject d, object basevalue)
|
private static object CoerceMaxPageCount(DependencyObject d, object baseValue)
|
||||||
{
|
{
|
||||||
var intValue = (int) basevalue;
|
var intValue = (int) baseValue;
|
||||||
return intValue < 1 ? 1 : intValue;
|
return intValue < 1 ? 1 : intValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,11 +160,11 @@ public class Pagination : Control
|
|||||||
public static readonly DependencyProperty PageIndexProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty PageIndexProperty = DependencyProperty.Register(
|
||||||
nameof(PageIndex), typeof(int), typeof(Pagination), new PropertyMetadata(ValueBoxes.Int1Box, OnPageIndexChanged, CoercePageIndex), ValidateHelper.IsInRangeOfPosIntIncludeZero);
|
nameof(PageIndex), typeof(int), typeof(Pagination), new PropertyMetadata(ValueBoxes.Int1Box, OnPageIndexChanged, CoercePageIndex), ValidateHelper.IsInRangeOfPosIntIncludeZero);
|
||||||
|
|
||||||
private static object CoercePageIndex(DependencyObject d, object basevalue)
|
private static object CoercePageIndex(DependencyObject d, object baseValue)
|
||||||
{
|
{
|
||||||
if (d is not Pagination pagination) return 1;
|
if (d is not Pagination pagination) return 1;
|
||||||
|
|
||||||
var intValue = (int) basevalue;
|
var intValue = (int) baseValue;
|
||||||
return intValue < 1
|
return intValue < 1
|
||||||
? 1
|
? 1
|
||||||
: intValue > pagination.MaxPageCount
|
: intValue > pagination.MaxPageCount
|
||||||
@@ -275,6 +274,7 @@ public class Pagination : Control
|
|||||||
public override void OnApplyTemplate()
|
public override void OnApplyTemplate()
|
||||||
{
|
{
|
||||||
_appliedTemplate = false;
|
_appliedTemplate = false;
|
||||||
|
|
||||||
base.OnApplyTemplate();
|
base.OnApplyTemplate();
|
||||||
|
|
||||||
_buttonLeft = GetTemplateChild(ElementButtonLeft) as Button;
|
_buttonLeft = GetTemplateChild(ElementButtonLeft) as Button;
|
||||||
@@ -286,12 +286,13 @@ public class Pagination : Control
|
|||||||
_buttonLast = GetTemplateChild(ElementButtonLast) as RadioButton;
|
_buttonLast = GetTemplateChild(ElementButtonLast) as RadioButton;
|
||||||
_jumpNumericUpDown = GetTemplateChild(ElementJump) as NumericUpDown;
|
_jumpNumericUpDown = GetTemplateChild(ElementJump) as NumericUpDown;
|
||||||
|
|
||||||
_buttonFirst.GroupName = groupName;
|
|
||||||
_buttonLast.GroupName = groupName;
|
|
||||||
|
|
||||||
CheckNull();
|
CheckNull();
|
||||||
|
|
||||||
|
_buttonFirst.Content = "1";
|
||||||
|
_buttonFirst.GroupName = _groupName;
|
||||||
|
_buttonLast.GroupName = _groupName;
|
||||||
_appliedTemplate = true;
|
_appliedTemplate = true;
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,11 +398,11 @@ public class Pagination : Control
|
|||||||
|
|
||||||
private RadioButton CreateButton(int page)
|
private RadioButton CreateButton(int page)
|
||||||
{
|
{
|
||||||
return new()
|
return new RadioButton
|
||||||
{
|
{
|
||||||
Style = PaginationButtonStyle,
|
Style = PaginationButtonStyle,
|
||||||
Content = page.ToString(),
|
Content = page.ToString(),
|
||||||
GroupName = groupName
|
GroupName = _groupName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
xmlns:ex="clr-namespace:HandyControl.Tools.Extension">
|
xmlns:ex="clr-namespace:HandyControl.Tools.Extension">
|
||||||
|
|
||||||
<Style x:Key="PaginationButtonStyle" BasedOn="{StaticResource BaseStyle}" TargetType="RadioButton">
|
<Style x:Key="PaginationButtonStyle" BasedOn="{StaticResource BaseStyle}" TargetType="RadioButton">
|
||||||
<Setter Property="GroupName" Value="1"/>
|
|
||||||
<Setter Property="MinWidth" Value="30"/>
|
<Setter Property="MinWidth" Value="30"/>
|
||||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
|
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
|
||||||
@@ -82,7 +81,7 @@
|
|||||||
<interactivity:EventToCommand Command="interactivity:ControlCommands.Selected" PassEventArgsToCommand="True" />
|
<interactivity:EventToCommand Command="interactivity:ControlCommands.Selected" PassEventArgsToCommand="True" />
|
||||||
</interactivity:RoutedEventTrigger>
|
</interactivity:RoutedEventTrigger>
|
||||||
</interactivity:Interaction.Triggers>
|
</interactivity:Interaction.Triggers>
|
||||||
<RadioButton Name="PART_ButtonFirst" Content="1" IsChecked="True" Style="{TemplateBinding PaginationButtonStyle}"/>
|
<RadioButton Name="PART_ButtonFirst" IsChecked="True" Style="{TemplateBinding PaginationButtonStyle}"/>
|
||||||
<Border Name="PART_MoreLeft" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
<Border Name="PART_MoreLeft" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
||||||
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center"/>
|
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center"/>
|
||||||
</Border>
|
</Border>
|
||||||
@@ -90,7 +89,7 @@
|
|||||||
<Border Name="PART_MoreRight" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
<Border Name="PART_MoreRight" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
||||||
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center"/>
|
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center"/>
|
||||||
</Border>
|
</Border>
|
||||||
<RadioButton Name="PART_ButtonLast" Content="10" Style="{TemplateBinding PaginationButtonStyle}"/>
|
<RadioButton Name="PART_ButtonLast" Style="{TemplateBinding PaginationButtonStyle}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Button x:Name="PART_ButtonRight" MinWidth="30" Padding="10,8" hc:IconElement.Geometry="{StaticResource RightGeometry}" hc:BorderElement.CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource CornerRadiusSplitConverter},ConverterParameter='0,1,1,0'}" Margin="-1,0,0,0" Command="interactivity:ControlCommands.Next"/>
|
<Button x:Name="PART_ButtonRight" MinWidth="30" Padding="10,8" hc:IconElement.Geometry="{StaticResource RightGeometry}" hc:BorderElement.CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource CornerRadiusSplitConverter},ConverterParameter='0,1,1,0'}" Margin="-1,0,0,0" Command="interactivity:ControlCommands.Next"/>
|
||||||
<hc:NumericUpDown x:Name="PART_Jump" IsEnabled="{TemplateBinding IsJumpEnabled}" Visibility="{TemplateBinding IsJumpEnabled,Converter={StaticResource Boolean2VisibilityConverter}}" Margin="6,0,0,0" Maximum="{Binding MaxPageCount,RelativeSource={RelativeSource TemplatedParent}}" Minimum="1"/>
|
<hc:NumericUpDown x:Name="PART_Jump" IsEnabled="{TemplateBinding IsJumpEnabled}" Visibility="{TemplateBinding IsJumpEnabled,Converter={StaticResource Boolean2VisibilityConverter}}" Margin="6,0,0,0" Maximum="{Binding MaxPageCount,RelativeSource={RelativeSource TemplatedParent}}" Minimum="1"/>
|
||||||
|
|||||||
@@ -13194,7 +13194,6 @@
|
|||||||
<Setter Property="MinHeight" Value="20" />
|
<Setter Property="MinHeight" Value="20" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="PaginationButtonStyle" BasedOn="{StaticResource BaseStyle}" TargetType="RadioButton">
|
<Style x:Key="PaginationButtonStyle" BasedOn="{StaticResource BaseStyle}" TargetType="RadioButton">
|
||||||
<Setter Property="GroupName" Value="1" />
|
|
||||||
<Setter Property="MinWidth" Value="30" />
|
<Setter Property="MinWidth" Value="30" />
|
||||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
<Setter Property="Background" Value="{DynamicResource RegionBrush}" />
|
||||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
|
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
|
||||||
@@ -13268,7 +13267,7 @@
|
|||||||
<interactivity:EventToCommand Command="interactivity:ControlCommands.Selected" PassEventArgsToCommand="True" />
|
<interactivity:EventToCommand Command="interactivity:ControlCommands.Selected" PassEventArgsToCommand="True" />
|
||||||
</interactivity:RoutedEventTrigger>
|
</interactivity:RoutedEventTrigger>
|
||||||
</interactivity:Interaction.Triggers>
|
</interactivity:Interaction.Triggers>
|
||||||
<RadioButton Name="PART_ButtonFirst" Content="1" IsChecked="True" Style="{TemplateBinding PaginationButtonStyle}" />
|
<RadioButton Name="PART_ButtonFirst" IsChecked="True" Style="{TemplateBinding PaginationButtonStyle}" />
|
||||||
<Border Name="PART_MoreLeft" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
<Border Name="PART_MoreLeft" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
||||||
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center" />
|
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center" />
|
||||||
</Border>
|
</Border>
|
||||||
@@ -13276,7 +13275,7 @@
|
|||||||
<Border Name="PART_MoreRight" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
<Border Name="PART_MoreRight" Cursor="No" Margin="-1,0,0,0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" Padding="10,0">
|
||||||
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center" />
|
<hc:SimpleText FontWeight="Bold" Foreground="{DynamicResource SecondaryTextBrush}" Text="..." VerticalAlignment="Center" />
|
||||||
</Border>
|
</Border>
|
||||||
<RadioButton Name="PART_ButtonLast" Content="10" Style="{TemplateBinding PaginationButtonStyle}" />
|
<RadioButton Name="PART_ButtonLast" Style="{TemplateBinding PaginationButtonStyle}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Button x:Name="PART_ButtonRight" MinWidth="30" Padding="10,8" hc:IconElement.Geometry="{StaticResource RightGeometry}" hc:BorderElement.CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource CornerRadiusSplitConverter},ConverterParameter='0,1,1,0'}" Margin="-1,0,0,0" Command="interactivity:ControlCommands.Next" />
|
<Button x:Name="PART_ButtonRight" MinWidth="30" Padding="10,8" hc:IconElement.Geometry="{StaticResource RightGeometry}" hc:BorderElement.CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource CornerRadiusSplitConverter},ConverterParameter='0,1,1,0'}" Margin="-1,0,0,0" Command="interactivity:ControlCommands.Next" />
|
||||||
<hc:NumericUpDown x:Name="PART_Jump" IsEnabled="{TemplateBinding IsJumpEnabled}" Visibility="{TemplateBinding IsJumpEnabled,Converter={StaticResource Boolean2VisibilityConverter}}" Margin="6,0,0,0" Maximum="{Binding MaxPageCount,RelativeSource={RelativeSource TemplatedParent}}" Minimum="1" />
|
<hc:NumericUpDown x:Name="PART_Jump" IsEnabled="{TemplateBinding IsJumpEnabled}" Visibility="{TemplateBinding IsJumpEnabled,Converter={StaticResource Boolean2VisibilityConverter}}" Margin="6,0,0,0" Maximum="{Binding MaxPageCount,RelativeSource={RelativeSource TemplatedParent}}" Minimum="1" />
|
||||||
|
|||||||
Reference in new issue
Block a user