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

问题描述

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

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:

在 WPF 表单关闭时运行代码

但我需要一些方向.

谢谢你=)

推荐答案

就是这个XAML

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

以及 ClosingClosed 事件的代码

and code for both the Closing and Closed events

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

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

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

07-29 12:30