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

VulpesRank #55 · 29.2K reputationPosted May 30, 2011, 1:47 PM EDT
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 Brigitta40 reputationPosted May 31, 2011, 2:42 AM EDT
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!
VulpesRank #55 · 29.2K reputationPosted May 31, 2011, 3:40 AM EDT
What's the full error message?
Kevin Brigitta40 reputationPosted May 31, 2011, 4:00 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 31, 2011, 5:55 AM EDT
"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 Brigitta40 reputationPosted May 31, 2011, 6:31 AM EDT
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!