all,, I have a project that is built in VB.Net 2010 and WPF 4. I have an option to return to a sign-in screen, yet th开发者_运维问答is option can only be accessed from a separate (quit confirmation) window. This function can be called when one of about a hundred windows are open behind the quit confirmation window.
What I want to do is close the quit confirmation window, and the other window that is open, but open the sign-in window. I know to use "Me.Close()" to close the quit confirmation window, and I know how to open the sign-in window, but I do not know how to close the other window that is open.
Help?
Couldn't you give the constructor of the quit-confirmation-window a reference to the window it should close when that option is chosen?
Edit: Two examples of how to do it:
Often you'd like to open a confirmation-dialogue when the window is being closed, so you'd create it in the Closing event-handler like this:
private void Window_Closing(object sender, CancelEventArgs e)
{
ConfirmationDialog diag = new ConfirmationDialog();
diag.ShowDialog();
switch (diag.Result)
{
...
}
}
Here your window waits for the confirmation dialogue to return (diag.Show
would not wait), if that is the case you do not need any information about the window in the dialogue itself. (Result
is a custom property that you can define in your dialogue if the DialogResult
bool is not differentiated enough)
If your dialogue is opened whenever and you cannot wait for it to return you can create it with a reference:
private void OpenConfirmDialog()
{
ConfirmationDialog diag = new ConfirmationDialog(this);
diag.Show()
}
and in your dialogue code:
public ConfirmationDialog(Window owner)
{
Owner = owner;
}
public void OpenWelcomeScreenThing()
{
this.Close();
Owner.Close();
new WelcomeScreen().Show();
}
or something like that. Alternatively you could work with events as well.
精彩评论