Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF MessageBox not waiting for result [WPF NotifyIcon]

I am using WPF NotifyIcon to create a System Tray service. When I show a messagebox, it shows up for half a second and then disappears immediately without waiting for input.

This kind of situation has happened before, and the usual advice is to use an overload which accepts a Window parameter. However, being a System Tray service, there is no window to use as a parent, and null is not accepted in its place.

Is there any way to make the MessageBox wait for user input short of creating a custom MessageBox window myself?

like image 914
Gigi Avatar asked Mar 14 '14 10:03

Gigi


1 Answers

You don't need to create a proxy window for this. Just add MessageBoxOptions.DefaultDesktopOnly to your message box and it will fire on your desktop without disappearing.

Example

MessageBox.Show("My Message", "Title", MessageBoxButton.OK, 
    MessageBoxImage.Information, MessageBoxResult.OK, 
    MessageBoxOptions.DefaultDesktopOnly);
like image 146
Xcalibur37 Avatar answered Oct 18 '22 14:10

Xcalibur37