I have an application with 2 Windows. I removed the StartupUri
in the App.xaml. Instead I subscribed for the Startup
-Event to show my Windows.
My two windows are called Login
and MainWindow
.
In the Startup
-Event I have the following code:
private void App_OnStartup(object sender, StartupEventArgs e)
{
var login = new Login();
var dialogResult = login.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value)
{
var mainWindow = new MainWindow();
mainWindow.ShowDialog();
}
}
When I start my application the Login-Window appears. On the Login-Window there's just one Button
. On a click on this Button
the following code will be executed:
private void ButtonClick(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
My expectations are now, that on a click on the Button
in the Login-Window the MainWindow appears. Instead the complete application is terminated.
If I set a BreakPoint in the StartUp-Event at if (dialogResult.HasValue && dialogResult.Value)
I can enter the brackets and the code in the brackets is executing, but the MainWindow does not appear.
Any ideas why this happens?
I can solve this problem by calling the MainWindow in the Click-Event of the Login-Window like.
var mainWindow = new MainWindow();
mainWindow.Show();
Close();