I have a C#/WPF application that consists of a mainwindow and a system tray icon. I have configured App.xaml with ShutdownMode="OnExplicitShutdown" in order to keep the application running in the system tray upon closing the main window.
In the context menu of the system tray icon, I have menu items bound to methods that re-open the main Window:
private void SysTray_Information_Click(object sender, RoutedEventArgs e)
{
var newWindow = new MainWindow();
newWindow.Show();
MainWindow.Focus();
}
I would like to add to these methods a check to see if the mainwindow is already being displayed (hasn't been closed). Otherwise it will be possible to open multiple copies of the mainwindow. How can I achieve this?