WPF 进度条继续动画
我正在使用 WPF 的进度条并将该值设置为最大值。 但是,当到达时,动画(即绿色效果)将继续。
我怎样才能阻止它并有一个完整的绿色条,没有任何动画?
例如,采用这个 :
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
<Grid>
<ProgressBar Height="30" Name="progressBar1" VerticalAlignment="Top" Minimum="0" Maximum="100" />
</Grid>
</Window>
和 :
public partial class Window1 : Window
{
private double _min;
private double _max;
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_min = progressBar1.Minimum;
_max = progressBar1.Maximum;
Thread thread = new Thread(Start);
thread.Start();
}
private void Start()
{
for (double i = _min; i <= _max; i++)
{
Thread.Sleep(50);
double value = i;
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => progressBar1.Value = value));
}
}
}
当线程完成时,我总是可以在进度条上看到动画(绿色条上的白色效果)
提前感谢您的帮助
I'm using the progress bar of WPF and set the value until the max value.
But, when reached, the animation (that's the green effect) continues.
How can I stop it and have a full filled green bar, without any animation ?
for example, take this :
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
<Grid>
<ProgressBar Height="30" Name="progressBar1" VerticalAlignment="Top" Minimum="0" Maximum="100" />
</Grid>
</Window>
and :
public partial class Window1 : Window
{
private double _min;
private double _max;
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_min = progressBar1.Minimum;
_max = progressBar1.Maximum;
Thread thread = new Thread(Start);
thread.Start();
}
private void Start()
{
for (double i = _min; i <= _max; i++)
{
Thread.Sleep(50);
double value = i;
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => progressBar1.Value = value));
}
}
}
When thread has finished, I can always see the animation on the progress bar (the white effect on the green bar)
Thanks in advance for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不完全确定你的意思,但也许你需要的是将 ProgressBar 的 IsInminateate 属性设置为 false。如果这不起作用,请给我们一些代码来进一步帮助您!
编辑:
该动画是 Windows Aero 风格的一部分,一些设计师花了大笔钱来......错误地设计它!因此,您不能简单地使用属性来删除动画。您可以通过编辑控件模板来更改现有进度条的视觉外观。下面是WPF ProgressBar的整个控件模板。注意:您需要所有资源、Window.Themes 的 xmlns 引用,并且必须设置对PresentationFramwork.Aero dll 的引用。我插入了一条评论,您可以在其中进行更改。
在第二个和第三个梯度停止处将颜色 FF000000 更改为 00000000,白色辉光消失。我尝试实现一个触发器,该触发器首先显示动画,但在 Value==Maximum 时停止它,但我失败了。他人?
I am not entirely sure what you mean, but perhaps what you need is to set the ProgressBar's IsIndeterminate property to false. If that does not work, then please give us some code to help you further!
EDIT:
The animation is part of the Windows Aero style and some designer was payed big bucks to ... err desgin it! So you cannot simply remove the animation using a property. You can alter the visual appearance of existing ProgressBars by editing their controltemplate. Below is the entire controltemplate of the WPF ProgressBar. Mind: you need all the Resources, the xmlns reference to Window.Themes and you must set a reference to the PresentationFramwork.Aero dll. I inserted a comment where you can make the change.
Change the color FF000000 to 00000000 on the second and third gradientstops and the white glow disappears. I tried to implement a trigger that will show the animation at first, but stops it when Value==Maximum, but I failed. Someone else?
同意“闪光”动画让一些用户感到困惑。它可以被删除,而不会破坏上面 Dabblernl:s 答案所做的 IsInminated 功能。
使用您可以在 Dabblernl:s 帖子中找到的 Aero 样式,我将: 替换
为:
... 并添加了一个新的 MultiConverter:
所以我有效地所做的是将 Microsoft:s ProgressBarHighlightConverter 替换为我自己的一个,它依赖于原始转换器当且仅当进度条:s 值小于其最大值时。
Agreed that the "gleam" animation is confusing to some users. It CAN be removed without destroying the IsIndeterminate-functionality which Dabblernl:s answer above does.
Using the Aero style that you can find in Dabblernl:s post I replaced:
with:
...and added a new MultiConverter:
So what I've effectively done is replace Microsoft:s ProgressBarHighlightConverter with one of my own that falls back on the original converter if and only if the progress bar:s value is lesser than that of its maximum.
我认为这是windows aero的一个功能...所有进度条都有这个效果,别以为它可以停止...
I think that is a feature of windows aero ... all progress bars have this effect , don't think it can be stopped ...