WPF 进度条动画速度
我注意到 WPF 进度栏和 WinForms 进度栏完全填满所需的时间存在差异。
完全填充,就像在 Form 和 WPF 中将值设置为 100 一样,我们可以注意到 WinForms 平滑地填充栏,而 WPF 立即填充它。
我想知道是否有一个属性我们可以在模板中编辑来更改它。
希望我说清楚了,如果有人愿意,我也可以发布视频。
编辑
这是我的视频谈论,注意到区别了吗?
编辑2
用计时器填充进度条?
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);
}
}
}
可以吗?它可以在任何地方使用吗?
请随意更改它。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个想法是进度条报告实际进度 - 而不是经过的时间。它并不是仅仅指示正在发生某事的动画。
基本原则是将
Value
绑定到 DataContext 类上的属性,并在出现进度里程碑时更新该值。您可以使用计时器使其以指定的速率填充 - 这是一个示例:
和代码:
The idea is that a progress bar reports actual progress - not time elapsed. It's not intended to be an animation that just indicates something is happening.
The basic principle is that you bind
Value
to a property on your DataContext class, and update that value whenever a progress milestone occurs.You can make it fill at a specified rate using a timer - here is an example:
And the code:
请参阅我的答案 如何更新进度条使其平滑增加?
它与扩展方法类似,但使用一种行为,以便您可以将进度条与报告进度的内容分离。 :)
See my answer on How to update a progress bar so it increases smoothly?
It's similar to the extension method, but uses a behavior so that you can decouple the progress bar from the thing that's reporting progress. :)
看起来只有 WPF 进度条有问题(或没有)...另一位用户报告了它 此处
通过添加扩展方法解决了这个问题:
设置值后调用Refresh()方法解决了这个问题。
但是,我发现即使在应用了刷新()方法之后,进度条也会在每次运行时跳跃(从不同的值)。
使用backgroundworker和reportprogress给出准确的结果,没有“跳跃”。
It looks like it's a problem (or not) with only WPF progress bar...another user reported it here
It was solved by adding an extension method:
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".