This is a migrated thread and some comments may be shown as answers.

RadSplitButton: How to get the Key pressen when DropDownClosed

1 Answer 77 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 10 Jun 2014, 02:41 PM
I'm using a WPF RadSplitButton and I'd like to to some special handling, when the DropDownClosed happens:

If the User presses ESC to close the dropped down content of my RadSplitButton, I'd like to do some undo operations. How do I get the Key that has caused the RadSplitBotton to close it's DropDown section?

In the Event Handler

        private void RadSplitButton_DropDownClosed(object sender, RoutedEventArgs e)
        {}

there is only RoutedEventArgs, which does not contain the pressed Button.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 13 Jun 2014, 08:40 AM
Hi Peter,

In order to achieve your requirement you can use the Keyboard.IsKeyPressed() method. The method excepts a value from the Key enumeration and returns bool value. Here is an example:
private void splitBtn_DropDownClosed(object sender, RoutedEventArgs e)
{
    if (Keyboard.IsKeyDown(Key.Escape))
    {
        // do something
    }
}

If you want to get the explicit pressed key you can implement a method for this operation.
private Key GetPressedKey()
{
    var allKeys = Enum.GetValues(typeof(Key));
    Key pressedKey = Key.None;
    foreach (Key currentKey in allKeys)
    {
        if (currentKey != Key.None && Keyboard.IsKeyDown((Key)currentKey))
        {
            return currentKey;
        }
    }
    return pressedKey;
}

I hope this helps.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Buttons
Asked by
Peter
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or