WPF中的Window.ShowDialog()的HasValue与Value事件(全网目前独一)

WPF中的Window.ShowDialog()打开的窗口中的按钮Close()事件

我经常会使用ShowDialog().Value;这个遇到实现下面的功能时,ShowDialog()出的窗体Close()时,并不能返回值。
错误代码如下:
 0 AddDataWay addDataWay = new AddDataWay();
 1 if (addDataWay.ShowDialog().Value)  // 
 2             {
 3                 int selectedWay = addDataWay.SelectWay();
 4                 if (selectedWay == 1)
 5                 {
 6                 }
 7                 else
 8                 {
 9                 }
10             }
跟改为:
 0 AddDataWay addDataWay = new AddDataWay();
1
if (addDataWay.ShowDialog().HasValue) // 2 { 3 int selectedWay = addDataWay.SelectWay(); 4 if (selectedWay == 1) 5 { 6 } 7 else 8 { 9 } 10 }
AddDataWay窗口代码:
 1 public partial class AddDataWay : DXWindow
 2     {
 3         #region 成员变量
 4         public static int selectedWay=1;  // 选择方式默认云端
 5         #endregion
 6 
 7         public AddDataWay()
 8         {
 9             this.InitializeComponent();
10         }
11 
12         private void DXWindow_Loaded(object sender, RoutedEventArgs e)
13         {
14         }
15 
16         /// <summary>
17         /// 云端-0
18         /// </summary>
19         /// <param name="sender"></param>
20         /// <param name="e"></param>
21         private void ImportFromTheCloud_Click(object sender, RoutedEventArgs e)
22         {
23             selectedWay = 0;
24             this.Close();
25         }
26 
27         /// <summary>
28         /// 本地-1
29         /// </summary>
30         /// <param name="sender"></param>
31         /// <param name="e"></param>
32         private void ImportFromTheLocal_Click(object sender, RoutedEventArgs e)
33         {
34             selectedWay = 1;
35             this.Close();
36         }
37     }

 

WPF中的Window.ShowDialog()的HasValue与Value事件(全网目前独一)

上一篇:$(function(){});和window.onload=function(){}的区别?


下一篇:在 Node.js 上运行 Flutter Web 应用和 API