delegate
//
private WillHide willHide;
//
this.willHide =
//
private
this.win2.Hide();
}

e.Cancel =
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, this.willHide);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
namespace ClosingDemo
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
delegate void WillHide();
private Window2 win2 = new Window2();
private WillHide willHide;
public Window1()
{
InitializeComponent();
Test();
}
private void HideWin2()
{
this.win2.Hide();
}

private void Test()
{
App.Current.MainWindow = this;
App.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
this.willHide = new WillHide(this.HideWin2);
this.win2.Closing += new CancelEventHandler(win2_Closing);
this.btnShowWin2.Click += new RoutedEventHandler(btnShowWin2_Click);

this.win2.Show();
}
void btnShowWin2_Click(object sender, RoutedEventArgs e)
{
this.win2.Show();
}
void win2_Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, this.willHide);
}
}
}