2012-01-18 81 views
0

我已经从parentWindow(非模态)打开子窗口 - 实现“等待”的最佳方法是什么,以便parentWindow知道何时childWindow已关闭?出于几个原因,我不能使用showDialog()。我尝试了一个while循环(测试childWindow的可见性属性),但它只是打破(没有例外 - 但只是不打开childWindow)。这是多线程的情况吗?需要知道非模态窗口何时关闭

+0

为什么不能使用模态对话框? – Matten 2012-01-18 12:31:30

回答

4

什么是实现一个“等待”,使parentWindow 会知道什么时候childWindow已经关闭了最好的方法?

您可以使用事件,以便在子窗口关闭时通知父窗口。例如,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(); 
+0

非常感谢Ken。正是我在找的。出于好奇 - 这是用lambda写的吗? – 2012-01-18 13:09:32

+1

是的,它是lambda表达式。与标准事件处理程序相比,它更简洁明了,但另一方面,您不能轻易使用' - ='运算符来分离事件。 – ken2k 2012-01-18 13:15:28

+0

我明白了。非常感谢。与我正在对lambda进行的修订很好地结合在一起。我仍然很困惑发件人和电子邮件来自哪里,但我会掌握它的。 – 2012-01-18 13:22:13

1

我认为你可以这样做:

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

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