关于WPF进度条当IsInminated设置为true时,我个人认为动画太快了。
我认为放慢动画速度并可能使内部栏更宽将有助于缓解这个问题。
有办法自定义这个吗?
编辑:添加代码
.xaml
<Window x:Class="IndeterminateProgressBarTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:IndeterminateProgressBarTest"
mc:Ignorable="d"
Title="MainWindow" Height="100" Width="700">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="Type">
<VisualState Name="Indeterminate">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<PointAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)">
<EasingPointKeyFrame KeyTime="0" Value="0,0"/>
<EasingPointKeyFrame KeyTime="0:0:0" Value="0,0"/>
<EasingPointKeyFrame KeyTime="1:0:0" Value="0,0"/>
</PointAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ProgressBar Name="progressBar" Width="600" Height="25" IsIndeterminate="True"/>
</Grid>
</Window>
.cs
namespace IndeterminateProgressBarTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
VisualStateManager.GoToElementState(progressBar, "Indeterminate", true);
}
}
}
最佳答案
您可以通过编辑名为“不确定”的 VisualState
来自定义“不确定”动画。下面是ProgressBar
当前默认Style下的VistalState
。
<VisualState x:Name="Indeterminate">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<EasingDoubleKeyFrame KeyTime="0" Value="0.25"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.25"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0.25"/>
</DoubleAnimationUsingKeyFrames>
<PointAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)">
<EasingPointKeyFrame KeyTime="0" Value="-0.5,0.5"/>
<EasingPointKeyFrame KeyTime="0:0:1" Value="0.5,0.5"/>
<EasingPointKeyFrame KeyTime="0:0:2" Value="1.5,0.5"/>
</PointAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
分别改变第二个和第三个KeyTime
来改变动画的速度。进一步的定制取决于您。
关于c# - 如何更改 WPF 中不确定进度条动画的速度和宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72779359/