Lets say we have a mainWindow for the application and we want a second window or usercontrole (whichever is best suited) as a settings window. How would we open this window and close it with a mvvmLight approach?
This is currently the code i use for opening a new window(s).
var settingWindow = new SettingsViewWindow();
settingWindow.Show();
This is currently the code i use for closing a window.
This.Close();
I don't know much about the userControle controle and when to use it. If you know a youtube video or a site i could read about it it would be appritacted. Or just simply drop an explanation.
Below is how i have structured the MenuItem Click Events. For the time beeing this is how i like to struckure my eventhandlers for buttons in general, and place them inside a descreptive regrion. If i know how i would place this bottom part in a spolier. ;)
private void btnNav_Click(object sender, RoutedEventArgs
{
if(sender == btnNavSettings)
{
OpenSettingsWindow();
}
else if(sender == btnNavExitApp)
{
ShutDownApplication();
}
}
/// <summary>
/// Opens a settings window.
/// Only on settings window can be open at time.
/// </summary>
private void OpenSettingsWindow()
{
if(GlobalVariabels.GUI_Variabels.SettingsWindowIsOpen != true)
{
var settingWindow = new SettingsViewWindow();
settingWindow.Show();
}
}
/// <summary>
/// Exit the application properly.
/// </summary>
private void ShutDownApplication()
{
Application.Current.Shutdown(0);
}