New to Telerik UI for WPF? Download free 30-day trial

Use Keyboard to Get User Response

When you have an application that uses RadWindow to get user response, it's common to alleviate the user experience by giving the user a chance to use the keyboard. For example, it's natural to accept response button by clicking the keyboard Enter button, and respectively to cancel response by pressing the ESC button. RadWindow addresses this issue by the ResponseButton attached property.

ResponseButton is an attached property that specifies the behavior of the default buttons part of RadWindow upon keystrokes.

  • Accept - Setting this value to any button part of the RadWindow will invoke the button's Click event whenever Enter is pressed.

  • Cancel - Setting this value to any button part of the RadWindow will invoke the button's Click event whenever ESC is pressed.

Here is an example of how to create a window that responds to Enter and ESC keyboard strokes. The example uses the RadWindow as a user control:

To learn more about how to use the RadWindow as user control read this topic.

<telerik:RadWindow x:Class="RadWindowSamples.RadWindowControl" 
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                   xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"> 
    <Grid> 
        <Grid.RowDefinitions> 
            <RowDefinition Height="100" /> 
            <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
        <Rectangle Grid.Row="0" 
                   Fill="LemonChiffon" 
                   Width="100" 
                   Height="100" /> 
        <StackPanel Grid.Row="1" 
                    Orientation="Horizontal"> 
            <Button Click="OnButtonAcceptClicked" 
                    Content="Accept" 
                    telerik:RadWindow.ResponseButton="Accept" /> 
            <Button Click="OnButtonCancelClicked" 
                    Content="Cancel" 
                    telerik:RadWindow.ResponseButton="Cancel" /> 
        </StackPanel> 
    </Grid> 
</telerik:RadWindow> 

private void OnButtonAcceptClicked(object sender, RoutedEventArgs e) 
{ 
    this.DialogResult = true; 
    this.Close(); 
} 
private void OnButtonCancelClicked(object sender, RoutedEventArgs e) 
{ 
    this.DialogResult = false; 
    this.Close(); 
} 
Private Sub OnButtonAcceptClicked(sender As Object, e As RoutedEventArgs) 
    Me.DialogResult = True 
    Me.Close() 
End Sub 
Private Sub OnButtonCancelClicked(sender As Object, e As RoutedEventArgs) 
    Me.DialogResult = False 
    Me.Close() 
End Sub 

See Also

In this article