SubWindow 子窗口代碼this
public partial class SubWindow : Window { public delegate void UpdateDelegate(); public UpdateDelegate myHandle; public SubWindow() { InitializeComponent(); this.Closed += SubWindow_Closed; } private void SubWindow_Closed(object sender, EventArgs e) { myHandle(); } }
主窗口代碼spa
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { SubWindow s = new SubWindow(); s.myHandle += Method1; s.Show(); } private void Method1() { MessageBox.Show("子窗口要關閉啦。咱們也要同步關閉了。"); this.Close(); } }