Hi 便携式家园,
请参考下面的例子。使用DispatcherTimer来实现。
public dingshiqishowbox()
{
InitializeComponent();
dt_Tick();
}
public void dt_Tick()
{
DispatcherTimer _timer = new DispatcherTimer();
TimeSpan _time = new TimeSpan();
_time = TimeSpan.FromSeconds(30);
_timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
{
button.Content ="还有 "+ _time.ToString("c")+"秒 关闭!";
if (_time == TimeSpan.Zero) _timer.Stop();
_time = _time.Add(TimeSpan.FromSeconds(-1));
}, Application.Current.Dispatcher);
_timer.Start();
}
Best Regards,
Yohann Lu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.