DialogResult的可以创建并显示为对话窗口后,只设置 [英] DialogResult can be set only after Window is created and shown as dialog
问题描述
我有一个主WPF窗口,当按钮被点击窗口上,一个命令被执行
假设该命令是SendToTableCommand
I have a main WPF window, mywindow.showDialog when a button is clicked on the window, a command is executed let's say the command is SendToTableCommand
protected virtual void SendToTableExecute(object o)
{
UIThread.BeginInvoke(new Action<object>(SendToTableExecuteUI),o);
}
private void SendToTableExecuteUI(object o)
{
if (o is Control)
{
m_OwningWindow = UIHelper.FindVisualParent<Window>((Control)o);
}
do sth...
if (m_OwningWindow != null)
{
//only set DialogResult when window is ShowDialog before
if(System.Windows.Interop.ComponentDispatcher.IsThreadModal)
m_OwningWindow.DialogResult = true;
}
}
不久以前, m_OwningWindow。的DialogResult = TRUE
抛出异常。所以我增加了一个检查是否使用IsThreadModal。它已经工作了一段时间,但现在m_OwningWindowdoes不敢靠近,因为IsThreadModal是假的。
Sometime ago, m_OwningWindow.DialogResult = true
throws exception. So I added an if check that uses IsThreadModal. It has worked for a while, but now m_OwningWindowdoes not close because IsThreadModal is false.
我不知道什么是解决问题的正确途径,并认为我没有正确处理它。
请帮助。在此先感谢
I do not know what's the right way to solve the issue and think I did not handle it properly. Please help. thanks in advance
推荐答案
贾森的答复想起一个解决办法的我。即使用window.close()的,然后加上窗口bool类型的财产,说OKClicked,更换任何地方设置的DialogResult与window.close()的; window.OKClicked = true或false。参考替换用window.OKClicked到window.DialogResult。
与解决方法有什么问题?谢谢
Jason's reply reminds me of a workaround. i.e. using Window.Close(), then add a bool type property on window, say OKClicked, replace anywhere that set DialogResult with window.Close(); window.OKClicked = true or false. replace reference to window.DialogResult with window.OKClicked. Any problem with the workaround? thanks
这篇关于DialogResult的可以创建并显示为对话窗口后,只设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!