Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

c# - Run code on WPF form close

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...