SubWindow 子窗口代码
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(); } }
主窗口代码
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(); } }
时间: 2025-01-03 22:34:35