Reputation: 4249
I have two WPF windows.
Window1's button calling Window2, Window2 updates something, and then I want to proceed exactly where I stopped in Window1.
This is the code in Window1 inside a button_Click:
Window2 window = new Window2();
window.Show();
* wait until Window2 closes
//continue with other actions
How do I wait?
I saw this: wpf c# button wait for a button press
But how can I pass it from a different (already closed) window?
Upvotes: 0
Views: 165
Reputation: 43311
Use Window.ShowDialog
method, it opens a window and and waits for window closing.
http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx
Nullable<bool> dialogResult = window.ShowDialog();
// Test dialogResult: it is true if dialog was closed by OK button
Windows used as modal dialogs are usually contain OK and Cancel buttons, and programmed by such way, that pressing OK returns true
from ShowDialog
methid.
See also: Creating a Modal Custom Dialog Box http://msdn.microsoft.com/en-us/library/aa969773.aspx
Upvotes: 2
Reputation: 18580
Use Window.ShowDialog()
instead of Show(). This will open a modal window and will wait till it closes
Upvotes: 0