【问题标题】:How would I make a cancel button work like the "X" button?如何使取消按钮像“X”按钮一样工作?
【发布时间】:2011-02-03 01:09:29
【问题描述】:

在我的 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?

【问题讨论】:

    标签: c# wpf xaml cancel-button


    【解决方案1】:

    将按钮的 IsCancel 属性设置为 True。

    【讨论】:

    • 非常感谢!您为我节省了数小时的头痛时间。
    • 它对我不起作用。我的情况完全相同,但即使我将 IsCanel 更改为 true,e 仍然不包含 Cancel();
    猜你喜欢
    • 2015-12-20
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多