子窗体关闭父窗体
原理为:打开子窗体时,把父窗体的引用传入到子窗体,然后在子窗体中对引用进行操作。
父窗体代码:
private void button1_Click(object sender, RoutedEventArgs e) { Window2 win = new Window2(this); win.Owner = this; win.ShowDialog(); }
子窗体代码:
Window1 win; public Window2(Window1 win1) { InitializeComponent(); win = win1; } private void button1_Click(object sender, RoutedEventArgs e) { this.Close(); win.Close(); }