2012-01-18 48 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 
    }