user1017882
user1017882

Reputation:

Need to know when a non-modal window has closed

I have opened childwindow from parentWindow (non-modal) - what's the best approach to achieving a 'wait' so that parentWindow will know when childWindow has closed? For a couple of reasons I cannot use showDialog(). I have tried a while loop (testing the childWindow's visibility property) but it just breaks (no exception - but just doesn't open childWindow). Is it a case of multi-threading??

Upvotes: 1

Views: 2865

Answers (2)

ken2k
ken2k

Reputation: 48975

what's the best approach to achieving a 'wait' so that parentWindow will know when childWindow has closed?

You could use events so the parent window is notified when the child window closes. For instance, there is the Closed event.

Window childWindow = new ....
childWindow.Closed += (sender, e) =>
    {
        // Put logic here
        // Will be called after the child window is closed
    };
childWindow.Show();

Upvotes: 5

Marco
Marco

Reputation: 57573

I think you can use this:

    public ShowChild()
    {
        childWindow child = new childWindow();
        child.Closed += new EventHandler(child_Closed);
        child.Show();
    }

    void child_Closed(object sender, EventArgs e)
    {
        // Child window closed
    }

Upvotes: 1

Related Questions