I have a WPF application, i need the MessageBox
to always be top most.
in win forms i would do something like that:
System.Windows.Forms.MessageBox.Show(new Form() { TopMost = true }, "sure you wanna save?", "confirm", MessageBoxButtons.YesNo)
but how do i do that in WPF?
i saw a few different answers but non of them work for me e.g:
MessageBox.Show(Application.Current.MainWindow, "Im always on top - of the main window");
My mainWindo
is null.
In my application the MessageBox
is opening from different pages- not windows
Any idea how i do it in the most simple way?
Use MessageBoxOptions.DefaultDesktopOnly and it keeps the MessageBox on top of the window.
MessageBox.Show("You entered an incorrect value. Try once more.", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Exclamation,MessageBoxResult.OK,MessageBoxOptions.DefaultDesktopOnly);
this.Dispatcher.Invoke((Action)(() =>
{
MessageBox.Show("Im always on top - of the main window");
}));
This will run it in the UI thread.Throw this in the method that shows the msg box.
Cheers, G
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With