我如何使取消按钮像“X"一样工作?按钮? [英] How would I make a cancel button work like the "X" button?
本文介绍了我如何使取消按钮像“X"一样工作?按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 XAML 文件中,我有一个窗口,我正在尝试制作它,因此无论用户单击X"按钮还是单击取消"按钮,行为都是相同的.
In my XAML file, I have a window and I am trying to make it so the behavior is the same whether the user clicks the "X" button, or if he clicks the "Cancel" button.
我的删节代码如下:
public partial class Dialog : Window
{
.
.
.
private void Window_Closing(object sender, CancelEventArgs e)
{
e.Cancel() = true; //Works as expected
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
e.Cancel() = true; //Compile error
}
}
所以我意识到我的问题是 RoutedEventArgs 没有 Cancel() 方法.有谁知道如何让 RoutedEventArgs 更像 CancelEventArgs?
So I realize that my problem is that RoutedEventArgs does not have a Cancel() method. Does anyone know how I can make RoutedEventArgs work more like CancelEventArgs?
推荐答案
将按钮的 IsCancel 属性设置为 True.
Set the IsCancel property of the button to True.
这篇关于我如何使取消按钮像“X"一样工作?按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文