I'm using WPF and I've got no main window (I've overwritten the OnStartup method). But when user clicks on some menu-item, I want to show the settings window.
App.xaml.cs:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
new MainEnvironment();
}
MainEnvironment.cs:
NotifyIcon notifyIcon;
Settings settings_wnd = new Settings(); // WPF window
public MainEnvironment()
{
notifyIcon = new NotifyIcon()
{
...
ContextMenu = new ContextMenu(new MenuItem[]
{
new MenuItem("Settings", contextMenu_settingsButton_Click)
})
};
}
void contextMenu_settingsButton_Click(object sender, EventArgs e)
{
if (!this.settings_wnd.IsVisible)
this.settings_wnd.Show();
else
this.settings_wnd.Activate();
}
Problem is that when user closes this window, the whole application exits too. Why? And how can I prevent that?
Thanks
The application is defaultly set to shutdown when all its windows are closed. You only need to add ShutdownMode="OnExplicitShutdown"
to your App.xaml file.
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