RadSplitButton: How to get the Key pressen when DropDownClosed

2 posts, 0 answers
  1. Peter
    Peter avatar
    37 posts
    Member since:
    Dec 2011

    Posted 10 Jun 2014 Link to this post

    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.

  2. Martin
    Martin avatar
    1042 posts

    Posted 13 Jun 2014 Link to this post

    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.

    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top