关闭窗体前触发事件
有时有关闭窗体前需要触发事件,如退出前自动备份、确认退出等
在窗体标记里添加Closing事件: Closing="Window_Closing"
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult key = MessageBox.Show(
"Are you sure you want to quit",
"Confirm",
MessageBoxButton.YesNo,
MessageBoxImage.Question,
MessageBoxResult.No);
e.Cancel = (key == MessageBoxResult.No);
}
转载请注明出处。