VS里DialogResult 表示窗口关闭后返回一个窗口的结果。在程序中一旦设置DialogResult的值,接下来就会自动执行close()的方法,所以没有必要写this.close(),并且也没有必要设定closing和closed事件,其执行顺序为DialogResult=true/false->closing事件->closed事件而在调用对话框的主程序中建议如下写法:
Win_Filter win = new Win_Filter();
win.ShowDialog();
result = (bool)win.DialogResult;
if (result==false)
{
Shared_Data.Sub_Info_VM.bDel_Open = bDel_Open;
Shared_Data.Sub_Info_VM.bDel_Limit = bDel_Limit;
}
//dialog
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Shapes;
namespace JPT_Tester
{
/// <summary>
/// Interaction logic for Win_Filter.xaml
/// </summary>
public partial class Win_Filter : Window
{
public Win_Filter()
{
InitializeComponent();
this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
this.DataContext = Shared_Data.Sub_Info_VM;
}
}
}