enhance: add IsMouseSelectable property for StepBar (#1142)

close #1142
This commit is contained in:
NaBian committed 2022-03-28 00:18:49 +08:00
1 parent 3e7bd22f32
commit 759abff637
6 files changed
+69 -40

No files matched your search

@@ -10663,12 +10663,14 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:StepBarItem">
<StackPanel>
<Border Background="{DynamicResource RegionBrush}" HorizontalAlignment="Center" CornerRadius="12" BorderThickness="2" BorderBrush="{TemplateBinding Foreground}" Height="24" MinWidth="24">
<TextBlock Foreground="{TemplateBinding Foreground}" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Index,RelativeSource={RelativeSource TemplatedParent}}" />
</Border>
<ContentPresenter HorizontalAlignment="Center" ContentTemplate="{Binding ItemTemplate,RelativeSource={RelativeSource AncestorType=hc:StepBar}}" TextElement.Foreground="{TemplateBinding Foreground}" Margin="0,4,0,0" />
</StackPanel>
<Border Background="Transparent">
<StackPanel>
<Border Background="{DynamicResource RegionBrush}" HorizontalAlignment="Center" CornerRadius="12" BorderThickness="2" BorderBrush="{TemplateBinding Foreground}" Height="24" MinWidth="24">
<TextBlock Foreground="{TemplateBinding Foreground}" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Index,RelativeSource={RelativeSource TemplatedParent}}" />
</Border>
<ContentPresenter HorizontalAlignment="Center" ContentTemplate="{Binding ItemTemplate,RelativeSource={RelativeSource AncestorType=hc:StepBar}}" TextElement.Foreground="{TemplateBinding Foreground}" Margin="0,4,0,0" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
@@ -10688,7 +10690,7 @@
</Setter.Value>
</Setter>
</Style>
<Style x:Key="StepBarItemVerticalLeft" BasedOn="{StaticResource StepBarItemBaseStyle}" TargetType="hc:StepBarItem">
<Style x:Key="StepBarItemVertical" BasedOn="{StaticResource StepBarItemBaseStyle}" TargetType="hc:StepBarItem">
<Setter Property="Margin" Value="0, 10" />
<Setter Property="Template">
<Setter.Value>
@@ -10715,7 +10717,7 @@
<ItemsPresenter VerticalAlignment="Bottom" />
</hc:SimplePanel>
</ControlTemplate>
<ControlTemplate x:Key="StepBarVerticalLeftControlTemplate" TargetType="hc:StepBar">
<ControlTemplate x:Key="StepBarVerticalControlTemplate" TargetType="hc:StepBar">
<hc:SimplePanel>
<ProgressBar Orientation="Vertical" Width="4" HorizontalAlignment="Left" Name="PART_ProgressBarBack" VerticalAlignment="Center" Margin="10,0,0,0" Style="{StaticResource ProgressBarFlat}" Background="{DynamicResource ThirdlyTextBrush}" RenderTransformOrigin="0.5,0.5">
<ProgressBar.RenderTransform>
@@ -10734,8 +10736,8 @@
<Setter Property="ItemsPanel" Value="{StaticResource UniformHorizontalItemsPanelTemplate}" />
<Style.Triggers>
<Trigger Property="Dock" Value="Left">
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVerticalLeft}" />
<Setter Property="Template" Value="{StaticResource StepBarVerticalLeftControlTemplate}" />
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVertical}" />
<Setter Property="Template" Value="{StaticResource StepBarVerticalControlTemplate}" />
<Setter Property="ItemsPanel" Value="{StaticResource UniformVerticalItemsPanelTemplate}" />
</Trigger>
<Trigger Property="Dock" Value="Bottom">
@@ -10745,8 +10747,8 @@
</Trigger>
<Trigger Property="Dock" Value="Right">
<Setter Property="FlowDirection" Value="RightToLeft" />
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVerticalLeft}" />
<Setter Property="Template" Value="{StaticResource StepBarVerticalLeftControlTemplate}" />
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVertical}" />
<Setter Property="Template" Value="{StaticResource StepBarVerticalControlTemplate}" />
<Setter Property="ItemsPanel" Value="{StaticResource UniformVerticalItemsPanelTemplate}" />
</Trigger>
</Style.Triggers>
@@ -29,7 +29,7 @@
<Button Command="{Binding PrevCmd}" CommandParameter="{Binding ElementName=PanelMain}" Width="180" Content="{ex:Lang Key={x:Static langs:LangKeys.Prev}}" Style="{StaticResource ButtonPrimary}"/>
<Button Command="{Binding NextCmd}" CommandParameter="{Binding ElementName=PanelMain}" Width="180" Margin="0,16,0,0" Content="{ex:Lang Key={x:Static langs:LangKeys.Next}}" Style="{StaticResource ButtonPrimary}"/>
</StackPanel>
<hc:StepBar Margin="0,0,0,32" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Dock="Bottom">
<hc:StepBar IsMouseSelectable="True" Margin="0,0,0,32" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Dock="Bottom">
<hc:StepBarItem Content="{ex:Lang Key={x:Static langs:LangKeys.Register}}"/>
<hc:StepBarItem Content="{ex:Lang Key={x:Static langs:LangKeys.BasicInfo}}"/>
<hc:StepBarItem Content="{ex:Lang Key={x:Static langs:LangKeys.UploadFile}}"/>
@@ -48,7 +48,7 @@
</DataTemplate>
</hc:StepBar.ItemTemplate>
</hc:StepBar>
<hc:StepBar Grid.Column="1" Grid.Row="3" ItemsSource="{Binding DataList}" Dock="Right">
<hc:StepBar IsMouseSelectable="True" Grid.Column="1" Grid.Row="3" ItemsSource="{Binding DataList}" Dock="Right">
<hc:StepBar.ItemTemplate>
<DataTemplate>
<StackPanel>
@@ -30,7 +30,22 @@ public class StepBar : ItemsControl
{
CommandBindings.Add(new CommandBinding(ControlCommands.Next, (s, e) => Next()));
CommandBindings.Add(new CommandBinding(ControlCommands.Prev, (s, e) => Prev()));
ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
AddHandler(SelectableItem.SelectedEvent, new RoutedEventHandler(OnStepBarItemSelected));
}
private void OnStepBarItemSelected(object sender, RoutedEventArgs e)
{
if (!IsMouseSelectable)
{
return;
}
if (e.OriginalSource is StepBarItem item)
{
SetCurrentValue(StepIndexProperty, item.Index - 1);
}
}
private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
@@ -151,6 +166,15 @@ public class StepBar : ItemsControl
set => SetValue(DockProperty, value);
}
public static readonly DependencyProperty IsMouseSelectableProperty = DependencyProperty.Register(
"IsMouseSelectable", typeof(bool), typeof(StepBar), new PropertyMetadata(ValueBoxes.FalseBox));
public bool IsMouseSelectable
{
get => (bool) GetValue(IsMouseSelectableProperty);
set => SetValue(IsMouseSelectableProperty, ValueBoxes.BooleanBox(value));
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
@@ -1,5 +1,4 @@
using System.Windows;
using System.Windows.Controls;
using HandyControl.Data;
namespace HandyControl.Controls;
@@ -7,7 +6,7 @@ namespace HandyControl.Controls;
/// <summary>
/// 步骤条单元项
/// </summary>
public class StepBarItem : ContentControl
public class StepBarItem : SelectableItem
{
/// <summary>
/// 步骤编号
@@ -23,12 +23,14 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:StepBarItem">
<StackPanel>
<Border Background="{DynamicResource RegionBrush}" HorizontalAlignment="Center" CornerRadius="12" BorderThickness="2" BorderBrush="{TemplateBinding Foreground}" Height="24" MinWidth="24">
<TextBlock Foreground="{TemplateBinding Foreground}" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Index,RelativeSource={RelativeSource TemplatedParent}}"/>
</Border>
<ContentPresenter HorizontalAlignment="Center" ContentTemplate="{Binding ItemTemplate,RelativeSource={RelativeSource AncestorType=hc:StepBar}}" TextElement.Foreground="{TemplateBinding Foreground}" Margin="0,4,0,0"/>
</StackPanel>
<Border Background="Transparent">
<StackPanel>
<Border Background="{DynamicResource RegionBrush}" HorizontalAlignment="Center" CornerRadius="12" BorderThickness="2" BorderBrush="{TemplateBinding Foreground}" Height="24" MinWidth="24">
<TextBlock Foreground="{TemplateBinding Foreground}" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Index,RelativeSource={RelativeSource TemplatedParent}}"/>
</Border>
<ContentPresenter HorizontalAlignment="Center" ContentTemplate="{Binding ItemTemplate,RelativeSource={RelativeSource AncestorType=hc:StepBar}}" TextElement.Foreground="{TemplateBinding Foreground}" Margin="0,4,0,0"/>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
@@ -50,7 +52,7 @@
</Setter>
</Style>
<Style x:Key="StepBarItemVerticalLeft" BasedOn="{StaticResource StepBarItemBaseStyle}" TargetType="hc:StepBarItem">
<Style x:Key="StepBarItemVertical" BasedOn="{StaticResource StepBarItemBaseStyle}" TargetType="hc:StepBarItem">
<Setter Property="Margin" Value="0, 10"/>
<Setter Property="Template">
<Setter.Value>
@@ -80,7 +82,7 @@
</hc:SimplePanel>
</ControlTemplate>
<ControlTemplate x:Key="StepBarVerticalLeftControlTemplate" TargetType="hc:StepBar">
<ControlTemplate x:Key="StepBarVerticalControlTemplate" TargetType="hc:StepBar">
<hc:SimplePanel>
<ProgressBar Orientation="Vertical" Width="4" HorizontalAlignment="Left" Name="PART_ProgressBarBack" VerticalAlignment="Center" Margin="10,0,0,0" Style="{StaticResource ProgressBarFlat}" Background="{DynamicResource ThirdlyTextBrush}" RenderTransformOrigin="0.5,0.5">
<ProgressBar.RenderTransform>
@@ -100,8 +102,8 @@
<Setter Property="ItemsPanel" Value="{StaticResource UniformHorizontalItemsPanelTemplate}"/>
<Style.Triggers>
<Trigger Property="Dock" Value="Left">
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVerticalLeft}"/>
<Setter Property="Template" Value="{StaticResource StepBarVerticalLeftControlTemplate}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVertical}"/>
<Setter Property="Template" Value="{StaticResource StepBarVerticalControlTemplate}"/>
<Setter Property="ItemsPanel" Value="{StaticResource UniformVerticalItemsPanelTemplate}"/>
</Trigger>
<Trigger Property="Dock" Value="Bottom">
@@ -111,8 +113,8 @@
</Trigger>
<Trigger Property="Dock" Value="Right">
<Setter Property="FlowDirection" Value="RightToLeft"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVerticalLeft}"/>
<Setter Property="Template" Value="{StaticResource StepBarVerticalLeftControlTemplate}"/>
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVertical}"/>
<Setter Property="Template" Value="{StaticResource StepBarVerticalControlTemplate}"/>
<Setter Property="ItemsPanel" Value="{StaticResource UniformVerticalItemsPanelTemplate}"/>
</Trigger>
</Style.Triggers>
@@ -10781,12 +10781,14 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:StepBarItem">
<StackPanel>
<Border Background="{DynamicResource RegionBrush}" HorizontalAlignment="Center" CornerRadius="12" BorderThickness="2" BorderBrush="{TemplateBinding Foreground}" Height="24" MinWidth="24">
<TextBlock Foreground="{TemplateBinding Foreground}" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Index,RelativeSource={RelativeSource TemplatedParent}}" />
</Border>
<ContentPresenter HorizontalAlignment="Center" ContentTemplate="{Binding ItemTemplate,RelativeSource={RelativeSource AncestorType=hc:StepBar}}" TextElement.Foreground="{TemplateBinding Foreground}" Margin="0,4,0,0" />
</StackPanel>
<Border Background="Transparent">
<StackPanel>
<Border Background="{DynamicResource RegionBrush}" HorizontalAlignment="Center" CornerRadius="12" BorderThickness="2" BorderBrush="{TemplateBinding Foreground}" Height="24" MinWidth="24">
<TextBlock Foreground="{TemplateBinding Foreground}" Style="{StaticResource TextBlockDefaultThiLight}" Text="{Binding Index,RelativeSource={RelativeSource TemplatedParent}}" />
</Border>
<ContentPresenter HorizontalAlignment="Center" ContentTemplate="{Binding ItemTemplate,RelativeSource={RelativeSource AncestorType=hc:StepBar}}" TextElement.Foreground="{TemplateBinding Foreground}" Margin="0,4,0,0" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
@@ -10806,7 +10808,7 @@
</Setter.Value>
</Setter>
</Style>
<Style x:Key="StepBarItemVerticalLeft" BasedOn="{StaticResource StepBarItemBaseStyle}" TargetType="hc:StepBarItem">
<Style x:Key="StepBarItemVertical" BasedOn="{StaticResource StepBarItemBaseStyle}" TargetType="hc:StepBarItem">
<Setter Property="Margin" Value="0, 10" />
<Setter Property="Template">
<Setter.Value>
@@ -10833,7 +10835,7 @@
<ItemsPresenter VerticalAlignment="Bottom" />
</hc:SimplePanel>
</ControlTemplate>
<ControlTemplate x:Key="StepBarVerticalLeftControlTemplate" TargetType="hc:StepBar">
<ControlTemplate x:Key="StepBarVerticalControlTemplate" TargetType="hc:StepBar">
<hc:SimplePanel>
<ProgressBar Orientation="Vertical" Width="4" HorizontalAlignment="Left" Name="PART_ProgressBarBack" VerticalAlignment="Center" Margin="10,0,0,0" Style="{StaticResource ProgressBarFlat}" Background="{DynamicResource ThirdlyTextBrush}" RenderTransformOrigin="0.5,0.5">
<ProgressBar.RenderTransform>
@@ -10852,8 +10854,8 @@
<Setter Property="ItemsPanel" Value="{StaticResource UniformHorizontalItemsPanelTemplate}" />
<Style.Triggers>
<Trigger Property="Dock" Value="Left">
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVerticalLeft}" />
<Setter Property="Template" Value="{StaticResource StepBarVerticalLeftControlTemplate}" />
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVertical}" />
<Setter Property="Template" Value="{StaticResource StepBarVerticalControlTemplate}" />
<Setter Property="ItemsPanel" Value="{StaticResource UniformVerticalItemsPanelTemplate}" />
</Trigger>
<Trigger Property="Dock" Value="Bottom">
@@ -10863,8 +10865,8 @@
</Trigger>
<Trigger Property="Dock" Value="Right">
<Setter Property="FlowDirection" Value="RightToLeft" />
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVerticalLeft}" />
<Setter Property="Template" Value="{StaticResource StepBarVerticalLeftControlTemplate}" />
<Setter Property="ItemContainerStyle" Value="{StaticResource StepBarItemVertical}" />
<Setter Property="Template" Value="{StaticResource StepBarVerticalControlTemplate}" />
<Setter Property="ItemsPanel" Value="{StaticResource UniformVerticalItemsPanelTemplate}" />
</Trigger>
</Style.Triggers>