Run code on WPF form close

前端 未结 1 742
[愿得一人]
[愿得一人] 2020-12-20 04:45

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

相关标签:
1条回答
  • 2020-12-20 04:56

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

    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.

    0 讨论(0)
提交回复
热议问题