调整代码
This commit is contained in:
@@ -201,6 +201,196 @@
|
||||
</Style>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--<ControlTemplate x:Key="HorizontalProgressTemplate" TargetType="{x:Type ProgressBar}">
|
||||
<ControlTemplate.Resources>
|
||||
<Storyboard x:Key="ProgressIndeterminateHorizontal" RepeatBehavior="Forever">
|
||||
<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
|
||||
x:Name="backgroundBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4">
|
||||
|
||||
-->
|
||||
<!-- 核心改变:命名为 PART_Track,WPF 原生接管容器 -->
|
||||
<!--
|
||||
<Grid x:Name="PART_Track">
|
||||
-->
|
||||
<!-- 正常状态进度条:命名为 PART_Indicator,不绑Width,WPF自动算比例! -->
|
||||
<!--
|
||||
<Border
|
||||
x:Name="PART_Indicator"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{TemplateBinding Foreground}"
|
||||
CornerRadius="3" />
|
||||
|
||||
-->
|
||||
<!-- Indeterminate 动画层:默认隐藏,充满整个宽度 -->
|
||||
<!--
|
||||
<Border
|
||||
x:Name="IndeterminateLayer"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="{TemplateBinding Foreground}"
|
||||
CornerRadius="3"
|
||||
Visibility="Collapsed" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsIndeterminate" Value="True" />
|
||||
<Condition Property="IsEnabled" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
-->
|
||||
<!-- 进入不确定状态时,隐藏原进度条,显示充满的动画层 -->
|
||||
<!--
|
||||
<Setter TargetName="PART_Indicator" Property="Visibility" Value="Collapsed" />
|
||||
<Setter TargetName="IndeterminateLayer" Property="Visibility" Value="Visible" />
|
||||
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
|
||||
<MultiTrigger.EnterActions>
|
||||
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateHorizontal}" />
|
||||
</MultiTrigger.EnterActions>
|
||||
<MultiTrigger.ExitActions>
|
||||
<RemoveStoryboard BeginStoryboardName="beginIndeterminate" />
|
||||
</MultiTrigger.ExitActions>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>-->
|
||||
<!--<ControlTemplate x:Key="ProgressVerticalTemplate" TargetType="{x:Type ProgressBar}">
|
||||
<ControlTemplate.Resources>
|
||||
<Storyboard x:Key="ProgressIndeterminateVertical" RepeatBehavior="Forever">
|
||||
<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
|
||||
x:Name="backgroundBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4">
|
||||
<Grid x:Name="BarGrid" VerticalAlignment="Bottom">-->
|
||||
<!-- 计算进度条宽度 -->
|
||||
<!--
|
||||
<Grid.Height>
|
||||
<MultiBinding Converter="{x:Static internal:ValueToRangeWidthConverter.Instance}" ConverterParameter="1">
|
||||
<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>
|
||||
<Setter TargetName="BarGrid" Property="Height" Value="auto" />
|
||||
<Setter TargetName="BarGrid" Property="VerticalAlignment" Value="Stretch" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
|
||||
<MultiTrigger.EnterActions>
|
||||
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateVertical}" />
|
||||
</MultiTrigger.EnterActions>
|
||||
<MultiTrigger.ExitActions>
|
||||
<RemoveStoryboard BeginStoryboardName="beginIndeterminate" />
|
||||
</MultiTrigger.ExitActions>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>-->
|
||||
|
||||
<!--<ControlTemplate x:Key="ProgressVerticalTemplate" TargetType="{x:Type ProgressBar}">
|
||||
<ControlTemplate.Resources>
|
||||
<Storyboard x:Key="ProgressIndeterminateVertical" RepeatBehavior="Forever">
|
||||
<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
|
||||
x:Name="backgroundBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4">
|
||||
<Grid x:Name="BarGrid" VerticalAlignment="Bottom">-->
|
||||
<!-- 计算进度条宽度 -->
|
||||
<!--
|
||||
<Grid.Height>
|
||||
<MultiBinding Converter="{x:Static internal:ValueToRangeWidthConverter.Instance}" ConverterParameter="1">
|
||||
<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>
|
||||
<Setter TargetName="BarGrid" Property="Height" Value="auto" />
|
||||
<Setter TargetName="BarGrid" Property="VerticalAlignment" Value="Stretch" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
|
||||
<MultiTrigger.EnterActions>
|
||||
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateVertical}" />
|
||||
</MultiTrigger.EnterActions>
|
||||
<MultiTrigger.ExitActions>
|
||||
<RemoveStoryboard BeginStoryboardName="beginIndeterminate" />
|
||||
</MultiTrigger.ExitActions>
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>-->
|
||||
|
||||
<ControlTemplate x:Key="HorizontalProgressTemplate" TargetType="{x:Type ProgressBar}">
|
||||
<ControlTemplate.Resources>
|
||||
<Storyboard x:Key="ProgressIndeterminateHorizontal" RepeatBehavior="Forever">
|
||||
@@ -210,50 +400,43 @@
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</ControlTemplate.Resources>
|
||||
|
||||
<Border
|
||||
x:Name="backgroundBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4">
|
||||
<Grid x:Name="BarGrid" HorizontalAlignment="Left">
|
||||
<!-- 计算进度条宽度 -->
|
||||
<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>
|
||||
<!-- 进度条 -->
|
||||
|
||||
<!-- 核心改变:命名为 PART_Track,WPF 原生接管容器 -->
|
||||
<Grid x:Name="PART_Track">
|
||||
<!-- 正常状态进度条:命名为 PART_Indicator,不绑Width,WPF自动算比例! -->
|
||||
<Border
|
||||
x:Name="borderProgress"
|
||||
x:Name="PART_Indicator"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{TemplateBinding Foreground}"
|
||||
CornerRadius="3" />
|
||||
</Grid>
|
||||
|
||||
<!-- Indeterminate 动画层:默认隐藏,充满整个宽度 -->
|
||||
<Border
|
||||
x:Name="IndeterminateLayer"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="{TemplateBinding Foreground}"
|
||||
CornerRadius="3"
|
||||
Visibility="Collapsed" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsIndeterminate" Value="True" />
|
||||
<Condition Property="IsEnabled" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter TargetName="BarGrid" Property="Width" Value="auto" />
|
||||
<Setter TargetName="BarGrid" Property="HorizontalAlignment" Value="Stretch" />
|
||||
<!-- 进入不确定状态时,隐藏原进度条,显示充满的动画层 -->
|
||||
<Setter TargetName="PART_Indicator" Property="Visibility" Value="Collapsed" />
|
||||
<Setter TargetName="IndeterminateLayer" Property="Visibility" Value="Visible" />
|
||||
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
|
||||
<MultiTrigger.EnterActions>
|
||||
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateHorizontal}" />
|
||||
@@ -264,6 +447,8 @@
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
|
||||
<ControlTemplate x:Key="ProgressVerticalTemplate" TargetType="{x:Type ProgressBar}">
|
||||
<ControlTemplate.Resources>
|
||||
<Storyboard x:Key="ProgressIndeterminateVertical" RepeatBehavior="Forever">
|
||||
@@ -273,47 +458,66 @@
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</ControlTemplate.Resources>
|
||||
|
||||
<Border
|
||||
x:Name="backgroundBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4">
|
||||
<Grid x:Name="BarGrid" VerticalAlignment="Bottom">
|
||||
<!-- 计算进度条宽度 -->
|
||||
<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" />
|
||||
|
||||
<!-- 这里不再使用 PART_Track 命名,避免WPF原生逻辑干预 -->
|
||||
<Grid x:Name="BarGrid">
|
||||
|
||||
<!-- 正常状态进度条:靠底对齐,通过 Converter 计算高度 -->
|
||||
<Border
|
||||
x:Name="borderProgress"
|
||||
VerticalAlignment="Bottom"
|
||||
Background="{TemplateBinding Foreground}"
|
||||
CornerRadius="3">
|
||||
<Border.Height>
|
||||
<!-- 将 ConverterParameter 改为 0,保证 100% 时完美充满 -->
|
||||
<MultiBinding Converter="{x:Static internal:ValueToRangeWidthConverter.Instance}" ConverterParameter="0">
|
||||
<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
|
||||
ElementName="BarGrid"
|
||||
Mode="OneWay"
|
||||
Path="ActualHeight" />
|
||||
</MultiBinding>
|
||||
</Border.Height>
|
||||
</Border>
|
||||
|
||||
<!-- Indeterminate 动画层:默认隐藏,充满整个高度 -->
|
||||
<Border
|
||||
x:Name="IndeterminateLayer"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{TemplateBinding Foreground}"
|
||||
CornerRadius="3"
|
||||
Visibility="Collapsed" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsIndeterminate" Value="True" />
|
||||
<Condition Property="IsEnabled" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter TargetName="BarGrid" Property="Height" Value="auto" />
|
||||
<Setter TargetName="BarGrid" Property="VerticalAlignment" Value="Stretch" />
|
||||
<!-- 切换状态时控制 Visibility 隐藏计算好的进度条,显示充满的动画层 -->
|
||||
<Setter TargetName="borderProgress" Property="Visibility" Value="Collapsed" />
|
||||
<Setter TargetName="IndeterminateLayer" Property="Visibility" Value="Visible" />
|
||||
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryIndeterminateGradientBrush}" />
|
||||
<MultiTrigger.EnterActions>
|
||||
<BeginStoryboard x:Name="beginIndeterminate" Storyboard="{StaticResource ProgressIndeterminateVertical}" />
|
||||
@@ -324,6 +528,87 @@
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<Style x:Key="CircularProgressBarStyle" TargetType="ProgressBar">
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryNormalBrush}" />
|
||||
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
|
||||
<Setter Property="Width" Value="100" />
|
||||
<Setter Property="Height" Value="100" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ProgressBar">
|
||||
<Viewbox>
|
||||
<Grid Width="100" Height="100">
|
||||
<!-- 底色轨道 -->
|
||||
<Ellipse
|
||||
Width="100"
|
||||
Height="100"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Stroke="{TemplateBinding Background}"
|
||||
StrokeThickness="10" />
|
||||
|
||||
<!-- 进度层 -->
|
||||
<Path
|
||||
x:Name="ProgressPath"
|
||||
RenderTransformOrigin="0.5,0.5"
|
||||
Stretch="None"
|
||||
Stroke="{TemplateBinding Foreground}"
|
||||
StrokeEndLineCap="Round"
|
||||
StrokeStartLineCap="Round"
|
||||
StrokeThickness="10">
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform x:Name="RotateTransform" Angle="0" />
|
||||
</Path.RenderTransform>
|
||||
<Path.Data>
|
||||
<MultiBinding Converter="{x:Static internal:ProgressToAngleConverter.Instance}">
|
||||
<Binding Path="Value" RelativeSource="{RelativeSource TemplatedParent}" />
|
||||
<Binding Path="Maximum" RelativeSource="{RelativeSource TemplatedParent}" />
|
||||
</MultiBinding>
|
||||
</Path.Data>
|
||||
</Path>
|
||||
|
||||
<!-- 文字显示(仅在非不确定模式下显示) -->
|
||||
<TextBlock
|
||||
x:Name="ValueText"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, StringFormat={}{0:0}%}" />
|
||||
</Grid>
|
||||
</Viewbox>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<!-- 不确定进度状态(转圈圈) -->
|
||||
<Trigger Property="IsIndeterminate" Value="True">
|
||||
<!-- 1. 隐藏文字 -->
|
||||
<Setter TargetName="ValueText" Property="Visibility" Value="Collapsed" />
|
||||
<!-- 2. 给 Path 一个固定的弧线数据 (大约 25% 长度) -->
|
||||
<!-- M 50,5 代表起点;A 45,45... 代表半径45的圆弧到 95,50 -->
|
||||
<Setter TargetName="ProgressPath" Property="Data" Value="M 50,5 A 45,45 0 0 1 95,50" />
|
||||
<!-- 3. 执行旋转动画 -->
|
||||
<Trigger.EnterActions>
|
||||
<BeginStoryboard Name="SpinAnimation">
|
||||
<Storyboard>
|
||||
<DoubleAnimation
|
||||
RepeatBehavior="Forever"
|
||||
Storyboard.TargetName="ProgressPath"
|
||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
|
||||
From="0"
|
||||
To="360"
|
||||
Duration="0:0:1" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</Trigger.EnterActions>
|
||||
<Trigger.ExitActions>
|
||||
<StopStoryboard BeginStoryboardName="SpinAnimation" />
|
||||
</Trigger.ExitActions>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type ProgressBar}">
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryGradientBrush}" />
|
||||
|
||||
Reference in New Issue
Block a user