我如何使取消按钮像“X”一样工作按钮?
在我的 XAML 文件中,我有一个窗口,我试图将其设置为无论用户单击“X”按钮还是单击“取消”按钮,行为都是相同的。
我的删节代码如下:
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 一样工作?
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.
My abridged code is below:
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
}
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将按钮的 IsCancel 属性设置为 True。
Set the IsCancel property of the button to True.