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;
}
}
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