当WPF关闭时执行代码 [英] Execute code when a WPF closes

查看:616
本文介绍了当WPF关闭时执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉使用事件处理程序,我想知道是否有人有可能或可能指示一些代码,显示如何使用将在关闭/关闭事件执行代码的事件处理程序?



我知道这可以由于这个回答的问题:



在WPF表单上关闭运行代码



但是我需要一些方向。 p>

谢谢=)

解决方案

只是这个XAML

 < Window ... Closing =Window_ClosingClosed =Window_Closed> 
...
< / Window>

关闭关闭事件

  private void Window_Closing(object sender,System.ComponentModel.CancelEventArgs e)
{
...
}

private void Window_Closed(object sender,EventArgs e)
{
....
}


I am not familiar with using event handlers, and I was wondering if anyone had or could direct me to some code that shows how to use an event handler that will execute code on the Close/Closed event?

I know this can be done because of this answered question:

Run code on WPF form close

But I need some direction.

Thank you =)

解决方案

It's just this XAML

<Window ... Closing="Window_Closing" Closed="Window_Closed">
    ...
</Window>

and code for both the Closing and Closed events

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    ...
}

private void Window_Closed(object sender, EventArgs e)
{
    ....
}

这篇关于当WPF关闭时执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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