WPF进度 [英] WPF Progressbar

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

问题描述

在我的WPF应用程序,我必须表明在计时器滴答事件进度的进展,对此我下面写,

  System.Windows.Forms.Timer定时器; 
公共主窗口()
{
定时器=新System.Windows.Forms.Timer();
timer.Interval = 1000;
this.timer.Tick + =新System.EventHandler(this.timer_Tick);
}



Load事件如下

 私人无效Window_Loaded(对象发件人,RoutedEventArgs E)
{
progressBar1.Minimum = 0;
progressBar1.Value = DateTime.Now.Second;
progressBar1.Maximum = 700;
timer.Start();
}

和在Tick事件最后

 私人无效timer_Tick(对象发件人,EventArgs五)
{
持续时间=新的持续时间(TimeSpan.FromSeconds(20));

//进度条动画
System.Windows.Media.Animation.DoubleAnimation DoubleAnimation是=新System.Windows.Media.Animation.DoubleAnimation(200.0,持续时间);
progressBar1.BeginAnimation(ProgressBar.ValueProperty,DoubleAnimation是);
}

当我执行我的计划进度显示了两三个酒吧,然后进度它停止增量。后来有在进度没有任何影响。出了什么问题在我的代码。请帮帮忙!..



问候
Sangeetha


解决方案

在我的 WPF 应用程序,我有... System.Windows.Forms.Timer定时器;




这是错误类型的定时器。使用 DispatcherTimer 代替。




当我执行我的计划进度显示了两三个酒吧的进展,然后停止




这让我吃惊,我也不会预料到在所有的工作。 <击>这意味着你可能有oher问题太像阻塞主(调度)线程。



您只设定值有一次,在Loaded事件:

  progressBar1.Value = DateTime.Now.Second; 

有是 progressBar1.Value 没有变化在Tick事件。所以,数字,它停止不动。


In my WPF application i have to show a progressbar progress with in a timer tick event, which i am writing as below,

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);
}

load event as below

private void Window_Loaded(object sender, RoutedEventArgs e)
{
      progressBar1.Minimum = 0;
      progressBar1.Value = DateTime.Now.Second;
      progressBar1.Maximum = 700;
      timer.Start();         
 }

And at last in tick event,

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);
}

When i execute my program progressbar shows the progress for two-three bars and then it stops increment. Later there is no effect in the progress at all. What went wrong in my code. Please help!..

Regards Sangeetha

解决方案

In my WPF application I have ... System.Windows.Forms.Timer timer;

That is the wrong type of timer. Use a DispatcherTimer instead.

When i execute my program progressbar shows the progress for two-three bars and then it stops

This surprises me, I wouldn't have expected it to work at all. This means you may have oher problems too, like blocking the main (dispatcher) thread.

You are only setting the Value once, in the Loaded event:

     progressBar1.Value = DateTime.Now.Second;

There is no change to progressBar1.Value in the Tick event. So it figures that it stops moving.

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

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