Files
ShrlAlgoToolkit/Melskin/Controls/ProgressBar.xaml

351 lines
18 KiB
Plaintext
Raw Normal View History

2025-07-31 20:12:01 +08:00
<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:decorations="clr-namespace:Melskin.Controls.Decorations"
2026-02-20 15:31:44 +08:00
xmlns:internal="clr-namespace:Melskin.Converters.Internal">
2025-07-11 09:20:23 +08:00
2025-12-28 11:47:54 +08:00
<!--#region SlotProgress-->
2026-02-20 15:31:44 +08:00
<ControlTemplate x:Key="SlotHorizontalProgressTemplate" TargetType="{x:Type ProgressBar}">
2025-07-11 09:20:23 +08:00
<ControlTemplate.Resources>
2026-02-20 15:31:44 +08:00
<Storyboard x:Key="ProgressIndeterminateHorizontal" RepeatBehavior="Forever">
2025-08-20 12:10:35 +08:00
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground.(Brush.RelativeTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
2025-07-31 20:12:01 +08:00
<EasingDoubleKeyFrame KeyTime="0" Value="-1" />
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1" />
2025-07-11 09:20:23 +08:00
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<decorations:SlotBorder
2026-02-20 15:31:44 +08:00
x:Name="backgroundBorder"
Padding="2"
2025-07-31 20:12:01 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
2026-02-20 15:31:44 +08:00
Intensity="0.7">
<Grid x:Name="BarGrid" HorizontalAlignment="Left">
2025-07-31 20:12:01 +08:00
<!-- 计算进度条宽度 -->
2025-07-11 09:20:23 +08:00
<Grid.Width>
2025-08-20 12:10:35 +08:00
<MultiBinding Converter="{x:Static internal:ValueToRangeWidthConverter.Instance}" ConverterParameter="7">
2025-07-31 20:12:01 +08:00
<Binding
Mode="OneWay"
Path="Minimum"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="Maximum"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="Value"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="ActualWidth"
RelativeSource="{RelativeSource AncestorType={x:Type decorations:SlotBorder}}" />
2025-07-11 09:20:23 +08:00
</MultiBinding>
</Grid.Width>
2025-07-31 20:12:01 +08:00
<!-- 背景模糊效果 -->
<Border
2026-02-20 15:31:44 +08:00
x:Name="borderBlur"
2025-07-31 20:12:01 +08:00
Background="{TemplateBinding Foreground}"
2026-02-20 15:31:44 +08:00
CornerRadius="3">
2025-07-11 09:20:23 +08:00
<Border.Effect>
2025-07-31 20:12:01 +08:00
<BlurEffect Radius="8" />
2025-07-11 09:20:23 +08:00
</Border.Effect>
</Border>
2025-07-31 20:12:01 +08:00
<!-- 进度条 -->
<Border
2026-02-20 15:31:44 +08:00
x:Name="borderProgress"
2025-07-31 20:12:01 +08:00
Background="{TemplateBinding Foreground}"
2026-02-20 15:31:44 +08:00
CornerRadius="3" />
2025-07-11 09:20:23 +08:00
</Grid>
</decorations:SlotBorder>
2025-07-11 09:20:23 +08:00
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsIndeterminate" Value="True" />
<Condition Property="IsEnabled" Value="True" />
</MultiTrigger.Conditions>
2026-02-20 15:31:44 +08:00
<Setter TargetName="BarGrid" Property="Width" Value="auto" />
<Setter TargetName="BarGrid" Property="HorizontalAlignment" Value="Stretch" />
2025-08-12 23:08:54 +08:00
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
<MultiTrigger.EnterActions>
2026-02-20 15:31:44 +08:00
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateHorizontal}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
2025-07-31 20:12:01 +08:00
<RemoveStoryboard BeginStoryboardName="beginIndeterminate" />
</MultiTrigger.ExitActions>
</MultiTrigger>
2025-07-11 09:20:23 +08:00
</ControlTemplate.Triggers>
</ControlTemplate>
2025-08-20 12:10:13 +08:00
<!--
Foreground: 控件的 Foreground 属性。
(Brush.RelativeTransform): 这个 Foreground 画刷Brush的 RelativeTransform 属性。
(TransformGroup.Children): 这个变换Transform的 Children 集合(这隐含地要求 RelativeTransform 必须是一个 TransformGroup
[3]: Children 集合中的第四个元素索引从0开始
(TranslateTransform.X): 这个元素的 X 属性(这隐含地要求第四个元素必须是一个 TranslateTransform
2025-07-11 09:20:23 +08:00
2025-08-20 12:10:13 +08:00
<LinearGradientBrush EndPoint="1,0" StartPoint="0,1" x:Key="PrimaryIndeterminateGradientBrush">
2025-08-20 12:10:35 +08:00
<GradientStop Color="{StaticResource PrimaryNormalColor}" Offset="0" />
2025-08-20 12:10:13 +08:00
<GradientStop Color="{StaticResource PrimaryVariantColor}" Offset="0.7" />
2025-08-20 12:10:35 +08:00
<GradientStop Color="{StaticResource PrimaryNormalColor}" Offset="0.8" />
2025-08-20 12:10:13 +08:00
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
</LinearGradientBrush>
-->
2026-02-20 15:31:44 +08:00
<ControlTemplate x:Key="SlotProgressVerticalTemplate" TargetType="{x:Type ProgressBar}">
2025-07-11 09:20:23 +08:00
<ControlTemplate.Resources>
2026-02-20 15:31:44 +08:00
<Storyboard x:Key="ProgressIndeterminateVertical" RepeatBehavior="Forever">
2025-08-20 12:10:13 +08:00
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground.(Brush.RelativeTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
2025-07-31 20:12:01 +08:00
<EasingDoubleKeyFrame KeyTime="0" Value="1" />
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="-1" />
2025-07-11 09:20:23 +08:00
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<decorations:SlotBorder
2026-02-20 15:31:44 +08:00
x:Name="backgroundBorder"
Padding="2"
2025-07-31 20:12:01 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
2026-02-20 15:31:44 +08:00
Intensity="0.7">
<Grid x:Name="BarGrid" VerticalAlignment="Bottom">
2025-07-31 20:12:01 +08:00
<!-- 计算进度条宽度 -->
2025-07-11 09:20:23 +08:00
<Grid.Height>
2025-08-20 12:10:13 +08:00
<MultiBinding Converter="{x:Static internal:ValueToRangeWidthConverter.Instance}" ConverterParameter="7">
2025-07-31 20:12:01 +08:00
<Binding
Mode="OneWay"
Path="Minimum"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="Maximum"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="Value"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="ActualHeight"
RelativeSource="{RelativeSource AncestorType={x:Type decorations:SlotBorder}}" />
2025-07-11 09:20:23 +08:00
</MultiBinding>
</Grid.Height>
2025-07-31 20:12:01 +08:00
<!-- 背景模糊效果 -->
<Border Background="{TemplateBinding Foreground}" CornerRadius="3">
2025-07-11 09:20:23 +08:00
<Border.Effect>
2025-07-31 20:12:01 +08:00
<BlurEffect Radius="8" />
2025-07-11 09:20:23 +08:00
</Border.Effect>
</Border>
2025-07-31 20:12:01 +08:00
<!-- 进度条 -->
<Border Background="{TemplateBinding Foreground}" CornerRadius="3" />
2025-07-11 09:20:23 +08:00
</Grid>
</decorations:SlotBorder>
2025-07-11 09:20:23 +08:00
<ControlTemplate.Triggers>
<!--<Trigger Property="IsIndeterminate" Value="True">
<Setter TargetName="BarGrid" Property="Height" Value="auto" />
<Setter TargetName="BarGrid" Property="VerticalAlignment" Value="Stretch" />
2025-08-12 23:08:54 +08:00
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
2025-07-11 09:20:23 +08:00
<Trigger.EnterActions>
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateVertical}" />
2025-07-11 09:20:23 +08:00
</Trigger.EnterActions>
<Trigger.ExitActions>
2025-07-31 20:12:01 +08:00
<RemoveStoryboard BeginStoryboardName="beginIndeterminate" />
2025-07-11 09:20:23 +08:00
</Trigger.ExitActions>
</Trigger>-->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsIndeterminate" Value="True" />
<Condition Property="IsEnabled" Value="True" />
</MultiTrigger.Conditions>
2026-02-20 15:31:44 +08:00
<Setter TargetName="BarGrid" Property="Height" Value="auto" />
<Setter TargetName="BarGrid" Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
<MultiTrigger.EnterActions>
2026-02-20 15:31:44 +08:00
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateVertical}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="beginIndeterminate" />
</MultiTrigger.ExitActions>
</MultiTrigger>
2025-07-11 09:20:23 +08:00
</ControlTemplate.Triggers>
</ControlTemplate>
2026-02-20 15:31:44 +08:00
<Style x:Key="SlotProgressBarStyle" TargetType="{x:Type ProgressBar}">
2025-08-12 23:08:54 +08:00
<Setter Property="Foreground" Value="{DynamicResource PrimaryGradientBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
2025-07-31 20:12:01 +08:00
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Height" Value="20" />
2025-08-12 23:08:54 +08:00
<Setter Property="HorizontalAlignment" Value="Stretch" />
2025-07-31 20:12:01 +08:00
<Setter Property="BorderThickness" Value="1" />
2025-12-28 11:47:54 +08:00
<Setter Property="Template" Value="{StaticResource SlotHorizontalProgressTemplate}" />
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="IsIndeterminate" Value="False" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryDisabledBrush}" />
</Trigger>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="Template" Value="{StaticResource SlotProgressVerticalTemplate}" />
<Setter Property="Width" Value="20" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Trigger>
</Style.Triggers>
</Style>
<!--#endregion-->
2026-02-20 15:31:44 +08:00
<ControlTemplate x:Key="HorizontalProgressTemplate" TargetType="{x:Type ProgressBar}">
2025-12-28 11:47:54 +08:00
<ControlTemplate.Resources>
2026-02-20 15:31:44 +08:00
<Storyboard x:Key="ProgressIndeterminateHorizontal" RepeatBehavior="Forever">
2025-12-28 11:47:54 +08:00
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground.(Brush.RelativeTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<EasingDoubleKeyFrame KeyTime="0" Value="-1" />
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Border
2026-02-20 15:31:44 +08:00
x:Name="backgroundBorder"
2025-12-28 11:47:54 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
2026-02-20 15:31:44 +08:00
CornerRadius="4">
<Grid x:Name="BarGrid" HorizontalAlignment="Left">
2025-12-28 11:47:54 +08:00
<!-- 计算进度条宽度 -->
<Grid.Width>
<MultiBinding Converter="{x:Static internal:ValueToRangeWidthConverter.Instance}" ConverterParameter="7">
<Binding
Mode="OneWay"
Path="Minimum"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="Maximum"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="Value"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="ActualWidth"
RelativeSource="{RelativeSource AncestorType={x:Type Border}}" />
</MultiBinding>
</Grid.Width>
<!-- 进度条 -->
<Border
2026-02-20 15:31:44 +08:00
x:Name="borderProgress"
2025-12-28 11:47:54 +08:00
Background="{TemplateBinding Foreground}"
2026-02-20 15:31:44 +08:00
CornerRadius="3" />
2025-12-28 11:47:54 +08:00
</Grid>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsIndeterminate" Value="True" />
<Condition Property="IsEnabled" Value="True" />
</MultiTrigger.Conditions>
2026-02-20 15:31:44 +08:00
<Setter TargetName="BarGrid" Property="Width" Value="auto" />
<Setter TargetName="BarGrid" Property="HorizontalAlignment" Value="Stretch" />
2025-12-28 11:47:54 +08:00
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
<MultiTrigger.EnterActions>
2026-02-20 15:31:44 +08:00
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateHorizontal}" />
2025-12-28 11:47:54 +08:00
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="beginIndeterminate" />
</MultiTrigger.ExitActions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
2026-02-20 15:31:44 +08:00
<ControlTemplate x:Key="ProgressVerticalTemplate" TargetType="{x:Type ProgressBar}">
2025-12-28 11:47:54 +08:00
<ControlTemplate.Resources>
2026-02-20 15:31:44 +08:00
<Storyboard x:Key="ProgressIndeterminateVertical" RepeatBehavior="Forever">
2025-12-28 11:47:54 +08:00
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground.(Brush.RelativeTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<EasingDoubleKeyFrame KeyTime="0" Value="1" />
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="-1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Border
2026-02-20 15:31:44 +08:00
x:Name="backgroundBorder"
2025-12-28 11:47:54 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
2026-02-20 15:31:44 +08:00
CornerRadius="4">
<Grid x:Name="BarGrid" VerticalAlignment="Bottom">
2025-12-28 11:47:54 +08:00
<!-- 计算进度条宽度 -->
<Grid.Height>
<MultiBinding Converter="{x:Static internal:ValueToRangeWidthConverter.Instance}" ConverterParameter="7">
<Binding
Mode="OneWay"
Path="Minimum"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="Maximum"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="Value"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="ActualHeight"
RelativeSource="{RelativeSource AncestorType={x:Type Border}}" />
</MultiBinding>
</Grid.Height>
<!-- 进度条 -->
<Border Background="{TemplateBinding Foreground}" CornerRadius="3" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsIndeterminate" Value="True" />
<Condition Property="IsEnabled" Value="True" />
</MultiTrigger.Conditions>
2026-02-20 15:31:44 +08:00
<Setter TargetName="BarGrid" Property="Height" Value="auto" />
<Setter TargetName="BarGrid" Property="VerticalAlignment" Value="Stretch" />
2025-12-28 11:47:54 +08:00
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
<MultiTrigger.EnterActions>
2026-02-20 15:31:44 +08:00
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateVertical}" />
2025-12-28 11:47:54 +08:00
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="beginIndeterminate" />
</MultiTrigger.ExitActions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="{x:Type ProgressBar}">
<Setter Property="Foreground" Value="{DynamicResource PrimaryGradientBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Height" Value="8" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="BorderThickness" Value="1" />
2025-10-10 11:19:58 +08:00
<Setter Property="Template" Value="{StaticResource HorizontalProgressTemplate}" />
2025-07-11 09:20:23 +08:00
<Style.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="IsIndeterminate" Value="False" />
2025-10-10 11:19:58 +08:00
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryDisabledBrush}" />
</Trigger>
2025-07-11 09:20:23 +08:00
<Trigger Property="Orientation" Value="Vertical">
2025-10-10 11:19:58 +08:00
<Setter Property="Template" Value="{StaticResource ProgressVerticalTemplate}" />
2025-12-28 11:47:54 +08:00
<Setter Property="Width" Value="8" />
2025-08-12 23:08:54 +08:00
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
2025-07-11 09:20:23 +08:00
</Trigger>
</Style.Triggers>
</Style>
2025-07-11 09:20:23 +08:00
</ResourceDictionary>