WPF中的计时器 [英] Timer in wpf
本文介绍了WPF中的计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public partial class MainWindow : Window
{
System.Timers.Timer t=new System.Timers.Timer();
t.Interval=5000;
public MainWindow()
{
this.InitializeComponent();
// Insert code required on object creation below this point.
}
private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
this.media1.Play();
//mel_Copy.Stop();
t.Enabled=true;
t.Tick+=new System.EventHandle(this.timer1_Tick); //here
//B1
}
private void timer1_Tick(object sender, System.EventArgs e)
{
this.media1.Stop();
}
}
}
我正在Expression Blend 3中编程,
我想在WPF中使用一个计时器,当用户单击button1时,事件会在5秒后发生(例如),但是WPF似乎没有
滴答事件! (t.Tick):confused::(
我添加了System.Timers;
我该怎么办?
I''m programming in Expression blend 3,
I want to use a timer in WPF that when the user clicks the button1, event occurs after 5 sec (for example), but it seems WPF does not have the
Tick event ! ( t.Tick) :confused: :(
I''ve added System.Timers;
What shall I do?
推荐答案
使用DispatcherTimer
对象而不是System.Timers.Timer
.顺便说一句,使用Google可以轻松回答.
Use theDispatcherTimer
object instead ofSystem.Timers.Timer
. BTW, this is EASILY answered by using google.
认为您正在寻找已用事件
请参见此链接 [
Hi,
Think you are looking for the Elapsed event
See this link[^]
Hope it helps :)
如果无法在XAML中进行设置,则需要按照文档中的说明在C#或VB.NET中进行设置.您发布了代码,因此必须在此处进行.
If you can''t set something in XAML, you need to set it in C# or VB.NET, as the documentation says. You posted code, so that''s where you have to do it.
这篇关于WPF中的计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文