处理 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()
释放所有非托管资源,并关闭所有拥有的 Window
s.
Close()
releases all unmanaged resources, and closes all owned Window
s.
您需要确定性处置的任何其他托管资源应从 关闭 事件.
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)