首页 新闻 会员 周边 捐助

WPF showDialog 关闭报错

0
[已解决问题] 解决于 2017-06-03 14:35

using FirstFloor.ModernUI.Windows.Controls;
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.Navigation;
using System.Windows.Shapes;

namespace Common.Helper
{
/// <summary>
/// Interaction logic for frmMessage.xaml
/// </summary>
public partial class frmMessage : ModernDialog
{
public string ReturnMsg = "";
public frmMessage(string msgTitle, string msg1, string msg2, string msgType, string msgDetail)
{
InitializeComponent();

try
{
// define the dialog buttons
this.Buttons = new Button[] { this.YesButton, this.NoButton,this.OkButton,this.CancelButton};
this.YesButton.Click += new System.Windows.RoutedEventHandler(this.btnYes_Click);
this.NoButton.Click += new System.Windows.RoutedEventHandler(this.btnNo_Click);
this.OkButton.Click += new System.Windows.RoutedEventHandler(this.btnConfirm_Click);
this.CancelButton.Click += new System.Windows.RoutedEventHandler(this.btnConfirm_Click);

this.Title = msgTitle;
this.lblMessage1.Text = msg1;
this.lblMessage2.Text = msg2;
if (msgType == "1")
{
this.YesButton.Visibility = Visibility.Hidden;
this.NoButton.Visibility = Visibility.Hidden;
this.OkButton.Visibility = Visibility.Visible;

}
else if (msgType == "2")
{
this.YesButton.Visibility = Visibility.Visible;
this.NoButton.Visibility = Visibility.Visible;
this.OkButton.Visibility = Visibility.Hidden; ;
}
if (msgDetail != "")
{
CancelButton.Visibility = Visibility.Visible;
CancelButton.Content = msgDetail;
}
}
catch (Exception ex)
{
string msg = Utility.UtilityHelper.GetFinalInnerException(ex).Message;
Utility.UtilityHelper.WriteLog("frmMessage " + msg, Utility.UtilityHelper.eLogCategory.UI, System.Diagnostics.TraceEventType.Error);
CommonHelper.CallMsgPopUp("Notice", CommonManager.GetMessage("30006"), "", "1", msg);
}

}

private void btnYes_Click(object sender, EventArgs e)
{
try
{
ReturnMsg = "YES";
this.DialogResult = true;
this.Close();
}
catch (Exception ex)
{
//this.Cursor = Cursors.Default;
string msg = Utility.UtilityHelper.GetFinalInnerException(ex).Message;
Utility.UtilityHelper.WriteLog("frmMessage/btnYes_Click " + msg, Utility.UtilityHelper.eLogCategory.UI, System.Diagnostics.TraceEventType.Error);
CommonHelper.CallMsgPopUp("Notice", CommonManager.GetMessage("30013"), "", "1", msg);
}
}

private void btnNo_Click(object sender, EventArgs e)
{
try
{
ReturnMsg = "NO";
this.DialogResult = true;
this.Close();
}
catch (Exception ex)
{
//this.Cursor = Cursors.Default;
string msg = Utility.UtilityHelper.GetFinalInnerException(ex).Message;
Utility.UtilityHelper.WriteLog("frmMessage/btnNo_Click " + msg, Utility.UtilityHelper.eLogCategory.UI, System.Diagnostics.TraceEventType.Error);
CommonHelper.CallMsgPopUp("Notice", CommonManager.GetMessage("30013"), "", "1", msg);
}
}

private void btnConfirm_Click(object sender, EventArgs e)
{
try
{
ReturnMsg = "OK";
this.DialogResult = true;
this.Close();
}
catch (Exception ex)
{
//this.Cursor = Cursors.Default;
string msg = Utility.UtilityHelper.GetFinalInnerException(ex).Message;
Utility.UtilityHelper.WriteLog("frmMessage/btnConfirm_Click " + msg, Utility.UtilityHelper.eLogCategory.UI, System.Diagnostics.TraceEventType.Error);
CommonHelper.CallMsgPopUp("Notice", CommonManager.GetMessage("30013"), "", "1", msg);
}
}
}
}

 

点击确认关闭窗口时 出现异常

异常信息如下

DialogResult can be set only after Window is created and shown as dialog.

WPF
愤青愤青的主页 愤青愤青 | 初学一级 | 园豆:4
提问于:2016-10-26 08:42
< >
分享
最佳答案
0

用插入代码..... 格式太乱 不愿意仔细看

奖励园豆:5
pkyou | 初学一级 |园豆:98 | 2016-10-27 16:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册