How would I make a cancel button work like the “X” button?
-
28-10-2019 - |
Pergunta
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?
Solução
Set the IsCancel property of the button to True.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow