close\" button. I just need to know in t" />
开发者

How to determine if window is disposed

I have a function in a WPF MainWindow1.Xaml when application shuts down. But in unknown cases user can close application in another way then using the "file > close" button. I just need to know in the "Closing" methode if the current MainWindow1.xaml is already disposed or not. But I could not find any 开发者_开发问答property.

Can you help me?


You can try

var source = PresentationSource.FromVisual(yourWindow)

If source is null or source.IsDisposed == true, that would indicate your Window has been closed.


You can attach to the Closed event on the Window. When this event is called the windows is closed. Actually I have to correct: According to the MSDN documentation it only means that you cannot prevent the window from closing when this event is called.
If listening to the Closed event is not good enough then this is another option: How do you tell if a WPF Window is closed?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜