PopUp window on a specific time in WPF?

2019-07-16 18:58发布

How can I create and show a popup window at a specific time in WPF? What I mean how to display the window on the side of system tray.

3条回答
冷血范
2楼-- · 2019-07-16 19:03

You might want to check out DispatcherTimer.

查看更多
Explosion°爆炸
3楼-- · 2019-07-16 19:14

You could use a timer if you're trying to make the thing popup in a certain number of hours/seconds/minutes (or work out how many hours/seconds/minutes are left until your specific time comes around).

private System.Windows.Threading.DispatcherTimer popupTimer;

// Whatever is going to start the timer - I've used a click event
private void OnClick(object sender, RoutedEventArgs e)
{
    popupTimer = new System.Windows.Threading.DispatcherTimer();

    // Work out interval as time you want to popup - current time
    popupTimer.Interval = specificTime - DateTime.Now;
    popupTimer.IsEnabled = true;
    popupTimer.Tick += new EventHandler(popupTimer_Tick);
}

void popupTimer_Tick(object sender, EventArgs e)
{
    popupTimer.IsEnabled = false;
    // Show popup
    // ......
}

Ok, so you also want to know how to do a notifier popup type thing, which maybe this article in CodeProject might help.

查看更多
Emotional °昔
4楼-- · 2019-07-16 19:21

Check out this question for firing an event at a set time.

查看更多
登录 后发表回答