在我的 WPF 应用程序中,我必须在计时器滴答事件中显示进度条进度,我如下编写,
System.Windows.Forms.Timer timer;
public MainWindow()
{
timer = new System.Windows.Forms.Timer();
timer.Interval = 1000;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
}
加载事件如下
private void Window_Loaded(object sender, RoutedEventArgs e)
{
progressBar1.Minimum = 0;
progressBar1.Value = DateTime.Now.Second;
progressBar1.Maximum = 700;
timer.Start();
}
最后在 tick 事件中,
private void timer_Tick(object sender, EventArgs e)
{
Duration duration = new Duration(TimeSpan.FromSeconds(20));
//progress bar animation
System.Windows.Media.Animation.DoubleAnimation doubleanimation = new System.Windows.Media.Animation.DoubleAnimation(200.0, duration);
progressBar1.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);
}
当程序的进度条显示两到三个条的进度然后停止递增。后来对进度完全没有影响。
为什么?
最佳答案
由于您的 ProgressBar
与任何特定行为无关,因此它看起来像是一个不确定 栏的工作。
This other SO question提供了一些关于它的见解。简而言之,它是一个 XAML 单行代码:
<!-- MinVal, MaxVal, Height needed for this to work -->
<ProgressBar x:Name="progressBar1" Margin="5" IsIndeterminate="True"
MinimumValue="0" MaximumValue="700" value="0" Height="20"/>
然后在代码中,你是这样的:
progressBar1.IsIndeterminate = true; // start animation
progressBar1.IsIndeterminate = false; // stop animation
关于c# - WPF 进度条在几条之后停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15429256/