错误:无法设置可见性或关闭窗口后无法调用Show或ShowDialog. [英] Error:Cannot set Visibility or call Show or ShowDialog after window has closed.

查看:867
本文介绍了错误:无法设置可见性或关闭窗口后无法调用Show或ShowDialog.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我收到上述错误.您能建议我解决方法吗?

这是代码:

Hello All,

I''m getting the above error.Can u suggest me the solution?

Here is code:

Preview prev= new Preview();
           prev.Title = "Preview";
           prev.Owner = App.Current.Windows[0];
           prev.ShowDialog();  //getting error here




在Preview类中,我正在使用一个函数.如果该函数中发生任何错误,我将关闭Preview.这可能是导致错误的原因.




in Preview class I''m using one function.If any error occurred in that function I closed Preview.Might be it''s a cause of error.

推荐答案

就是这样实际上,关闭窗口后就无法使用它.

通常的做法是:处理事件Closing或重写受保护的虚拟方法OnClosing取消关闭并隐藏窗口.这样,您将能够再次显示该窗口实例.要取消关闭,您需要为事件参数参数的属性Cancel分配true.请参阅:
http://msdn.microsoft.com/en-us/library/system.componentmodel. canceleventargs.aspx [ ^ ].

—SA
This is what it is. Practically, you cannot use a window after it was closed.

The usual practice is this: handle the event Closing or override the protected virtual method OnClosing to cancel closing and hide the window instead. This way, you will be able to show this instance of the window again. To cancel closing, you will need to assign true to the property Cancel of the event arguments parameter. Please see:
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.aspx[^].

—SA


这篇关于错误:无法设置可见性或关闭窗口后无法调用Show或ShowDialog.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆