WPF的形​​式接近运行code [英] Run code on WPF form close

查看:104
本文介绍了WPF的形​​式接近运行code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能自动运行一些code,当一个WPF窗体关闭?

How can I automatically run some code when a WPF form is closed?

推荐答案

只是附加一个事件处理程序的 Window.Closed 您的形式。

Just attach an event handler to Window.Closed for your form.

它也可以通过创建自定义的ICommand,并让它根据关闭事件触发做到这一点更MVVM友好的方式。这里是一个博客文章,描述这种方法

It's also possible to do this in a more MVVM-friendly approach by creating a custom ICommand, and having it fire based off the event. Here is a blog post describing this approach.

一旦你做到了这一点,你可以在你的视图模型命令窗体关闭时将触发。

Once you've done that, you can have a command on your ViewModel that will fire when the form closes.

这篇关于WPF的形​​式接近运行code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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