窗体程序(NewWindows)

public delegate void OkClickHandler(NewWindowsModel model);
public event OkClickHandler OkClickEvent;
private void btnOK_Click(object sender, System.Windows.RoutedEventArgs e)
 {
       var n = new NewWindowsModel()
        {
            Name = textBox1.Text,
             Formula = textBox2.Text
         };
         OkClickEvent(n);
         Close();
}

 

主体程序(窗体事件放在主体程序执行)

private void AddNewField(object sender, RoutedEventArgs e)
{
      var w = new NewWindows() { Owner = Application.Current.MainWindow};
      w.OkClickEvent += AddNewNode;
      w.ShowDialog();
}

 private void AddNewNode(NewWindowsModel model)
{
 ....

}