WPF ProgressBar 在更新太快时会失去光泽 - bug?
好吧,我在摆弄 WPF ProgressBar 控件时发现了一些相当奇怪的行为。该控件位于ListView控件的一列中,一般情况与 差别不大这个问题&本质上回答。
我通过多个属性(Min
、Max
、Value
)将 Progressbar
绑定到一个类,所有单向绑定明显地。这个其他类从另一个线程更新,并定期使用 INotifyPropertyChanged 接口让 ProgressBar 知道状态正在进行。这一切都很棒!
但这就是奇怪的地方。我的进度条失去了光泽......直到它达到 Max
(=100%) 值。然后它突然开始在绿色条上发出白色发光的东西,这非常烦人。我展示进步是有原因的,一旦你开始注意到它不存在,缺乏脉搏实际上会让人分心。
于是,我开始调试。我发现在我的线程处理中使用 Thread.Sleep(1000)
,它仍然隐藏了发光,但是如果我将它撞到 Thread.Sleep(1500)
发光就会出现总是带着疯狂的活力回来。之后,我尝试将进度单位转换为较小的数字,以便整数值需要更长的时间才能更改。最小 0,最大 100 仍然缺乏发光。最小 0,最大 10 使辉光恢复其全部活力。在所有情况下,达到 100% 所花费的工作量和时间都是相同的,但对于发光显示来说,这是一个非常明显的二元“是/否”效果。我唯一没有测试过的是,当 ProgressBar 未放置在此 ListView 控件内时是否也会发生这种情况。
我非常了解自己,无法理解 ProgressBar 控件(涉及 XAML)的深层 WPF 内部结构。所以我希望这里的任何人都知道这是否是一个已知的错误,他们偶然发现的问题,或者他们甚至可能知道如何解决/修复的问题。
我的机器运行 Windows 7,我正在 VS2010 中针对 .NET Framework 4 Client Profile 进行开发。
Ok, so I found some rather weird behaviour while messing around with the WPF ProgressBar control. This control is located in a column of a ListView control and the general situation differs little from this question & answer in its essence.
I bind Progressbar
to a class by means of several properties (Min
, Max
, Value
), all OneWay Bindings obviously. This other class is updated from another thread and regularly uses the INotifyPropertyChanged
interface to let the ProgressBar know the status is progressing. And this all works just great!
But here is where it gets odd. My ProgressBar loses its glow.. right upto the moment it reaches the Max
(=100%) value. Then it suddenly starts pulsing its white glowy stuff all over the green bar, and this is very annoying. I am showing progress with a reason, and the lack of a pulse is actually pretty distracting once you start to notice it not being there.
Thus, I set off to debug. I found that with Thread.Sleep(1000)
in my threads processing, it still hid the glow, but if I bump it to Thread.Sleep(1500)
the glow comes back at all times with a crazy vigour. After that, I tried translating my progress units to smaller numbers so the integer values would take longer to change. Min 0, Max 100 still has the lack of the glow. Min 0, Max 10 had the glow come back in its full vigor. In all cases, it is the same amount of work and time spent to reach 100%, but it is a very visible binary YES/NO effect with regards to the glow showing. The only thing I have not tested is whether it also happens when the ProgressBar is not placed inside of this ListView control.
I know myself well enough that I can't make sense of the deep WPF innards of the (XAML involved with the) ProgressBar control. So I was hoping anyone here knows whether this is a known bug, something they stumbled into, or something they might even know how to work around/fix.
My machine runs Windows 7, and I'm developing in VS2010 targeting .NET Framework 4 Client Profile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测你会失去光芒,因为你经常更新进度条。 每次设置新值时,进度条都会重新启动其发光动画(我想 - 我还没有测试过这一点,我正在胡思乱想)。
看来您可能想到了同样的事情并尝试解决它,但我不确定您是否已完全用尽所有可能性:
附言!如果您更新进度条的速度非常快,那么发光动画不运行也没关系。请记住,发光动画的目的只是表明应用程序仍在运行(机器尚未冻结),尽管进度(条)尚未移动。
如果进度移动得很快,那么它本身就是用户的视觉效果,所以此时不需要发光动画......
I would take a guess and say that you lose the glow because you are updating your progress bar to often. Every time you set a new value the progress bar restarts its glowing animation (I think - I haven't tested this, I'm writing off the top of my head).
It seems that you have perhaps thought of the same thing and tried to work around it, but I'm not sure you have fully exhausted all possibilities:
PS! If you update your progressbar very rapidly, then it is OK for the glow animation not to run. Remember that the glow animiation's purpose is only to show that the application is still running (machine hasn't frozen), despite the fact that the progress(bar) hasn't moved.
If the progress is moving quickly, then that on its own is a visual effect for the user, so there is no need to have the glow animation at that moment...