Articles in this section
Category / Section

How to achieve the default button behavior with ButtonAdv?

1 min read

In the ButtonAdv control, you can achieve the behavior of the IsDefault and IsCancel properties similar to MS Button. It can be achieved using the Click event of button on the “PreviewKeyDown” event of Main window. On clicking Enter on “Yes”, the click event of DefaultButton is invoked, and on clicking Esc on “Cancel”, the click event of CancelButton is invoked.

The following code example demonstrates how to achieve the default button behavior with ButtonAdv.

Code example: [XAML]

         <syncfusion:ButtonAdv
                x:Name="DefaultButton"
                Grid.Column="1"
                Width="100"
                Height="30"
                Margin="10"
                Label="Yes"
                SizeMode="Normal"
                SmallIcon="Default.png"
               />
            <syncfusion:ButtonAdv
                x:Name="CancelButton"
                Grid.Column="2"
                Width="100"
                Height="30"
                Margin="10"
                Label="Cancel"
                SizeMode="Normal"
                SmallIcon="Close.png"
             />

 

C#:

//Invoke PreviewKeyDown event.
 
this.PreviewKeyDown += new KeyEventHandler(CloseOnEscape);
 
private void CloseOnEscape(object sender, KeyEventArgs e)
{
      // on pressing Escape, CancelButton get invoked.
     if (e.Key == Key.Escape)
     {
       CancelButton_Click(sender, e);
     }
 
     //On pressing the Enter, DefaultButton get invoked.
     if (e.Key == Key.Enter)
     {
       DefaultButton_Click(sender, e);
     }
}
 
private void DefaultButton_Click(object sender, RoutedEventArgs e)
{
      MessageBox.Show("Enter key pressed, Default Button is activated", "Message");
}
 
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
      MessageBox.Show("Esc key pressed, Cancel Button is activated", "Message");
}
 
 
 

 

Screenshot:

The following screenshot illustrates the default button characteristics of the ButtonAdv control.

       

 

Sample: How to achieve the default Button behavior with ButtonAdv?

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied