父窗体
/// <summary>
/// 打开设置界面
/// </summary>
private void Set(object sender, RoutedEventArgs e)
{
Setting set = new Setting();
set.ChangeTextEvent += new ChangeTextHandler(FuncSettingClosed);//设置关闭弹框后执行的方法调用
set.ShowDialog();
}
/// <summary>
/// 设置窗口关闭时执行的方法
/// </summary>
void FuncSettingClosed()
{
//写你想调用的方法,如重新绑定数据源啊 改变某标签的值
//GetData();
}
子窗体
public delegate void ChangeTextHandler();//定义委托 关闭弹框调用父页面方法步骤01
public partial class Setting : Window{
public event ChangeTextHandler ChangeTextEvent;//关闭弹框调用父页面方法步骤02
/// <summary>
/// 关闭弹窗
/// </summary>
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
StrikeEvent();//关闭弹框调用父页面方法步骤03
this.Close();//关闭弹窗
}
/// <summary>
/// 重写右上角的关闭事件
/// </summary>
/// <param name="e"></param>
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
StrikeEvent();//关闭弹框调用父页面方法步骤03
}
/// <summary>
/// 触发事件改变MainWindow的值
/// //关闭弹框调用父页面方法步骤04
/// </summary>
private void StrikeEvent()
{
if (ChangeTextEvent != null)
{
ChangeTextEvent();
}
}
}