处理 WPF 窗口的正确方法是什么? [英] What is the correct way to dispose of a WPF window?

查看:35
本文介绍了处理 WPF 窗口的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WPF 窗口,我通过调用 Show() 从另一个窗口创建它,然后让它 Close() 自己.当窗口关闭时,我希望它死掉,调用它的析构函数,并删除它的所有子元素(例如计时器......).

I have a WPF window which I am creating from another window by calling Show(), then letting it Close() itself. When the window closes, I expect it to die, call its destructor, and delete all its child elements (such as timers..).

调用此类操作的正确方法是什么?

What is the correct way of invoking such an action?

推荐答案

Close() 释放所有非托管资源,并关闭所有拥有的 Windows.

Close() releases all unmanaged resources, and closes all owned Windows.

您需要确定性处置的任何其他托管资源应从 关闭 事件.

Any other managed resources you need deterministic disposal of should be handled from the Closed event.

参考

(注:删除了之前的答案,完全是错误的猜测)

(note: deleted previous answer, it was a completely wrong guess)

这篇关于处理 WPF 窗口的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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