Disabling commands, but have their shortcut key events bubble up the tree

7 posts, 0 answers
  1. Chris Anderson
    Chris Anderson avatar
    6 posts
    Member since:
    Sep 2012

    Posted 04 Sep 2012 Link to this post

    I want to be able to disable default commands on the RadRichTextBox (for example the SaveCommand command), and have their corresponding shortcut keys bubble up the visual tree (so the SaveCommand command's Ctrl+S shortcut can be captured at the Window level).  I've tried two methods of disabling a command:
    
    #1 - Disabling the command

    rtb.Commands.SaveCommand.Enabled = false;


    #2 - Handling the CommandExecuting event and cancelling the command

    void RadRichTextBoxEx_CommandExecuting(object sender, CommandExecutingEventArgs e)
    {
        if (e.Command is SaveCommand)
            e.Cancel = true;
    }


    Unfortunately these methods seem to still mark the event as handled, and the KeyDown event never gets raised up the visual tree.  It seems this is a bug - is there a workaround or fix for it?

    Thanks

    Chris Anderson
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 07 Sep 2012 Link to this post

    Hello Chris Anderson,

    As a whole, overriding key bindings is done as shown in this article

    However, there are some limitation and several bindings cannot be overriden. Unfortunately, Ctrl+S is one of them.

    I will log this for revision and we will expose a way to override all key bindigs as soon as possible.

    Please, excuse us for any inconvenience caused.

    Greetings,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Chris Anderson
    Chris Anderson avatar
    6 posts
    Member since:
    Sep 2012

    Posted 07 Sep 2012 Link to this post

    Hi Petya

    Thanks for your reply.  Moreso than being able to override the shortcut key (I don't want to have to do this for every use of the control), the behaviour that I actually want is that if I disable a command, it should no longer mark the KeyDown/KeyUp events has handled for the command's associated shortcut key.  As far as I can guess, this is what is happening, as despite the command being disabled, the RadRichTextBox control is still swallowing its associated shortcut keys, and not allowing the KeyDown/KeyUp events to bubble up the tree.

    To reproduce:

    1. Disable the SaveCommand command using one of the methods in my first post.
    2. Add a KeyDown event handler to the Window, which checks for the Ctrl+S shortcut key.
    3. Press Ctrl+S in the RadRichTextBox control.

    Current behaviour: the KeyDown event handler at the window level never sees the Ctrl+S shortcut.

    Expected behaviour: the KeyDown event handler at the window level should see the Ctrl+S shortcut, as the RadRichTextBox control should not be capturing it anymore. 

    Thanks

    Chris
  5. Itamar
    Itamar avatar
    5 posts
    Member since:
    Aug 2011

    Posted 11 Sep 2012 Link to this post

    Hi Petya,

    I also encountered the same issue (and need) to disable the Ctrl+S and handle the same with my own logic.
    A solution will be much appreciated
    Thanks,

    Itamar
  6. Boby
    Admin
    Boby avatar
    595 posts

    Posted 12 Sep 2012 Link to this post

    Hello Chris and Itamar,
    We introduced a change in the API, which should allow you to unregister application command bindings on RadRichTextBox instances. The fix will be provided as part of the 2012 Q2 SP2 release, expected any time now.
    To use it in your scenario, you will have to:
    • Remove RadRichTextBox's binding to ApplicationCommands.Save
    • Handle RadRichTextBox.PreviewEditorKeyDown event and set SuppressDefaultAction in the argument to 'true' to suppress the default input handler
    This is demonstrated in the attached project. Note that you should be able to build it with the binaries from the upcoming 2012 Q2 SP2.

    Don't hesitate to contact us if you have further questions.


    Kind regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Chris Anderson
    Chris Anderson avatar
    6 posts
    Member since:
    Sep 2012

    Posted 12 Sep 2012 Link to this post

    Awesome!  Thanks Boby!

    Chris
  8. Itamar
    Itamar avatar
    5 posts
    Member since:
    Aug 2011

    Posted 13 Sep 2012 Link to this post

    Great, looking forward to that.

    Itamar
Back to Top
UI for WPF is Visual Studio 2017 Ready