c# - 如何更改 WPF 中不确定进度条动画的速度和宽度?

标签 c# wpf xaml progress-bar

关于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/

相关文章:

c# - 从库类公开枚举

使用两个任意点之间的 ArcSegment 计算半圆的 WPF 数学

wpf - 在 XAML 中为 WPF 本地化扩展使用占位符

c# - 订阅长期对象事件时,我附加的 DependencyProperty 是否泄漏?

c# - Windows 8 XAML Metro App 中的基本 UserControl 类

c# - Linq GroupBy Max 并添加列

c# - 如何控制 MVVM WinRT/XAML Windows Store 应用程序中 ListView 的滚动位置?

从空闲状态返回时,WPF应用程序变慢

javascript - Workers 无法在 WPF 项目中嵌入的 HTML 页面中工作

c# - 从 Windows Phone 7 中的麦克风获取数据文件