原本想用委託實現的。可是又以爲沒有必要。this
方法以下:spa
public MainWindow() { InitializeComponent(); this.Closing += MainWindow_Closing; } private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { foreach (Window w in this.OwnedWindows) { if (w!=null) { w.Close(); } } MessageBox.Show("全部子窗口關閉完成。"); } private void Button_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < 10; i++) { SubWindow s = new SubWindow("sub window"+i.ToString()); s.Owner = this; s.Show(); } }