Hi all,
When my WPF application starts up, an immediate second window is shown to fill in login credentials.
What I would like to do now, is whenever this "login window" is active, I want to grey out and de-activate the first 'general' window (mainwindow). I also want it to always remain behind the login window (as if the mainwindow was locked until proper credentials were given).
Can anyone help me regarding this 'issue'?
Thanks in advance!
Kind regards.
Loading
VulpesPosted May 30, 2011, 5:47 PM
The login form will then be owned by the main form and will always appear on top of it:
LoginForm login = new LoginForm();
login.Owner = this;
login.Show();
this.IsEnabled = false; // disable main form
You then need to handle the login form's Closed event to re-enable the main form:
private void Window_Closed(object sender, EventArgs e)
{
this.Owner.IsEnabled = true;
this.Owner.Activate();
}
Kevin BrigittaPosted May 31, 2011, 10:31 AM
It does, actually, but when I add it anyway like this:
LoginWindow Login = new LoginWindow();
GeneralWindow.Show(); //which is the mainwindow
Login.Owner = this;
Login.Show();
this.IsEnabled = false;
it works perfectly.
I wasn't aware that the "GeneralWindow.Show();" was necessary.
Thank you very much for your help!
Greetz!
VulpesPosted May 31, 2011, 9:55 AM
"Cannot set Owner property to a Window that has not been shown previously"
When I tried it, I showed the MainWindow before the LoginWindow which explains why it works for me.
I thought you must be doing the same, as otherwise the question makes no sense, but evidently you're not?
Kevin BrigittaPosted May 31, 2011, 8:00 AM
VulpesPosted May 31, 2011, 7:40 AM
What's the full error message?
Kevin BrigittaPosted May 31, 2011, 6:42 AM
I tried to do as you said in the last post, and I don't get any syntax error (intellisense). But when I build/run the application, I get an 'XamlParseException' which was unhandled...
This exception is thrown from the moment I add the "loginwindow.owner = this;" code...
Any ideas?
Thanks!