How would I make a cancel button work like the “X” button?

风流意气都作罢 提交于 2019-12-22 14:32:36

问题


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?


回答1:


Set the IsCancel property of the button to True.



来源:https://stackoverflow.com/questions/4881760/how-would-i-make-a-cancel-button-work-like-the-x-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!