WPF进度条动画速度 [英] WPF Progress Bar Animation Speed

查看:82
本文介绍了WPF进度条动画速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到 WPF 进度条和 WinForms 进度条完全填满所需的时间存在差异.

完全填充,就像在 Forms 和 WPF 中将 Value 设置为 100 一样,可以注意到 WinForms 平滑地填充栏,而 WPF 立即填充.

我想知道是否有我们可以在模板中编辑的属性来更改它.

希望我说清楚了,如果有人想要,我也可以发布视频.

编辑

这是我正在谈论的视频,注意区别?

编辑 2

用计时器填充进度条?

使用系统;使用 System.Windows;使用 System.Windows.Controls;使用 System.Windows.Media.Animation;命名空间 WpfApplication2{公共部分类 MainWindow : 窗口{公共主窗口(){this.InitializeComponent();this.Title = "WPF 进度条演示";}私人空隙填充(int from,int to){持续时间 = 新的持续时间(TimeSpan.FromSeconds(0.5));DoubleAnimation doubleanimation = new DoubleAnimation(from, to, duration);progb.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);}私人无效fill_Click(对象发送者,RoutedEventArgs e){填充(0, 100);}}}

可以吗?它可以在任何地方使用吗?

随意更改它.

谢谢.

解决方案

它看起来像是(或不是)只有 WPF 进度条的问题...另一个用户报告了它这里

<块引用>

  1. WPF 控件,完全是进度条,当复制 当我测试复制一个大文件时,完整的 GUI 只是完全冻结.进度条运行不顺畅.它只是从 0 跳到 100.

通过添加扩展方法解决了:

//你的代码pbBar.Value = some_value;pbBar.Refresh();//你的代码公共静态类 ExtensionMethods{私有静态动作EmptyDelegate = delegate() { };公共静态无效刷新(此 UIElement uiElement){uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);}公共静态无效刷新输入(这个 UIElement uiElement){uiElement.Dispatcher.Invoke(DispatcherPriority.Input, EmptyDelegate);}}

设置值后调用 Refresh() 方法解决了问题.

但是,我发现即使在应用了 refresh() 方法之后,每次运行时进度条都会跳转(来自不同的值).

使用 backgroundworkerreportprogress 给出没有跳跃"的准确结果.

I've noticed that there is a difference in the time it takes for a WPF Progress Bar and a WinForms Progress Bar to fill completely.

Fill completely as in set the Value to 100 in both Forms and WPF, one can notice that WinForms fills the bar smoothly whereas the WPF fills it instantly.

I wanted to know if there is a property that we can edit in the templates to change that.

Hope I made it clear, I can post a video too if anyone wants.

EDIT

Here's a video of what I'm talking about, notice the difference ?

EDIT 2

Filling the progress bar with a timer ?

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace WpfApplication2
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            this.Title = "WPF Progress Bar Demo";
        }

        private void fill(int from, int to)
        {
            Duration duration = new Duration(TimeSpan.FromSeconds(0.5));
            DoubleAnimation doubleanimation = new DoubleAnimation(from, to, duration);
            progb.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
        }

        private void fill_Click(object sender, RoutedEventArgs e)
        {
            fill(0, 100);
        }
    }
}

Is that OK and will it work anywhere ?

Feel free to change it.

Thanks.

解决方案

It looks like it's a problem (or not) with only WPF progress bar...another user reported it here

  1. WPF Control, exactly progress bar, does not update itself when copying When I test to copy a big file, the complete GUI just completely freezes. The progress bar doesn’t run smoothly. It just jumps from 0 to 100.

It was solved by adding an extension method:

 //Your Code
    pbBar.Value = some_value;
    pbBar.Refresh();
 //Your Code

public static class ExtensionMethods
{
    private static Action EmptyDelegate = delegate() { };
    public static void Refresh(this UIElement uiElement)
    {
        uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
    }

    public static void RefreshInput(this UIElement uiElement)
    {
        uiElement.Dispatcher.Invoke(DispatcherPriority.Input, EmptyDelegate);
    }
}

Calling the Refresh() method after setting the value solved the issue.

But, what I found was even after applying the refresh() method, the progress bar jumps on each run (from different values).

Using a backgroundworker and reportprogress gives the exact result with no "jumps".

这篇关于WPF进度条动画速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆