PopUp window on a specific time in WPF?

2019-07-16 19:07发布

问题:

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.

回答1:

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.



回答2:

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



回答3:

You might want to check out DispatcherTimer.