如何更改WPF中不确定进度栏动画的速度和宽度?

发布于 2025-02-10 21:05:35 字数 2507 浏览 2 评论 0原文

关于WPF进度栏,当issindetermination设置为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);
        }
    }
}

Regarding the WPF Progress Bar when IsIndeterminate is set to true, I personally think the animation is too fast.

I think slowing the animation down and maybe making the internal bar wider would help ease this problem.

Is there anyway to customize this?

edit: added code

.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);
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2025-02-17 21:05:35

您可以通过编辑Visual Statate命名不确定的动画来自定义不确定的动画。以下是VistalStateprogressbar的当前默认样式中。

<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以更改动画速度。进一步的自定义取决于您。

You can customize the Indeterminate animation by editing VisualState named Indeterminate. The following is that VistalState in current default Style of ProgressBar.

<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>

Change 2nd and 3rd KeyTime respectively to change the speed of animation. Further customization is up to you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文