I am getting the following exception:
"Nullable object must have a value"
Everything was working when I was using
StartupURI="MainWindow.xaml
"
but I wanted to implement a login screen so I changed this to
Startup="Application_Startup"
and then created the following method in App.xaml.cs:
private void Application_Startup(object sender, StartupEventArgs e)
{
UpdateAccounts();
bool result = true;
///*
LoginWindow login = new LoginWindow();
result = login.ShowDialog().Value;
/* */
if (!result)
{
return;
}
MainWindow window = new MainWindow();
bool main = window.ShowDialog().Value;
}
Does anyone have any idea what is going on? Or any suggestions on what is the best practice for implementing login interface.
The exception is being thrown at
bool main = window.ShowDialog().Value;
Exception Stack Trace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Nullable`1.get_Value()
My MainWindow.xaml was my default window that was being loaded when app started, and it worked prefectly fine. It has a lot of code inside it. A couple listboxes, a couple combo boxes, month calendar. It also connects to an access database.
To me it seems like my Window is return from ShowDialog() straight away, without letting me set DialogResult.
Update: I don't get an exception if i change my code to:
private void Application_Startup(object sender, StartupEventArgs e)
{
UpdateAccounts();
bool result = true;
///*
LoginWindow login = new LoginWindow();
result = login.ShowDialog().Value;
/* */
if (!result)
{
return;
}
MainWindow window = new MainWindow();
window.ShowDialog();
}
but I also don't get my main window show up, and the app just closes after logging in.