Author Topic: WPF - How to close Dialog when ESC key is pressed - IsCancel="True"  (Read 3120 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
You need to have a close button that closes the dialog. You can implement this very easily. Then all you need to do is, mapping the ESC with the button. To do this, simply setting IsCancel="True" does the magic for you.

Here is the xaml code.

Code:
//Source Code Listing


<Button Width="65"  Height="22" IsCancel="True" Name="gui_closebutton" Content="Close"
Click="CloseButton_Click" ToolTip="Close the dialog"></Button>


Here is the event handler code in C#.

Code:
//Source Code Listing


public partial class MyWindow : Window
{

   private void CloseButton_Click(object sender, RoutedEventArgs e)
   {
      this.Close();
   }

}

« Last Edit: November 01, 2011, 05:42:27 pm by kathir »

 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1