Override RichTextBoxCommands

4 posts, 0 answers
  1. Charles
    Charles avatar
    41 posts
    Member since:
    Mar 2012

    Posted 19 Nov 2014 Link to this post

    Hi

    I want to change the behaviour of certain commands - as one example, I want to be able to execute ChangePageOrientationCommand in a protected document.  The current value of CanExecuteBehaviorInProtectedDocument for that command is CanExecuteBehaviorInProtectedDocument.Never.

    So, easy, right?  I can derive from ChangePageOrientationCommand and override CanExecuteBehaviorInProtectedDocument.  Done.

    Then what I'd like to do is derive from RichTextBoxCommands, override the virtual ChangePageOrientationCommand and set the public Commands dependency property on RadRichTextBox... but I can't - the RichTextBoxCommands constructor is internal.

    Is there an extensibility point I'm missing?  

    While I could just instantiate this new command elsewhere and point by ribbon button to this, I'd also like to subtly change the behavior of InsertCommand and DeleteCommand (so they don't execute in certain scenarios).  This is much harder, as they're called internally by keyboard and mouse handling.

    Thanks

    Charlie
  2. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 24 Nov 2014 Link to this post

    Hello Charles,

    I am afraid that creation of custom commands is not possible at this point. My suggestion for your scenario is to create your own command that will use the RadDocumentEditor to manipulate the document. RadDocumentEditor has properties like RespectDocumentProtection which will allow execution of its methods over protected document.

    Could you provide more information on what exactly is your scenario with Insert and Delete commands and how you would like to change the way they are executed. This way we will be able to assist you better.


    Regards,
    Mihail
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Charles
    Charles avatar
    41 posts
    Member since:
    Mar 2012

    Posted 24 Nov 2014 in reply to Mihail Link to this post

    Thanks - I had managed use solutions similar to yours to get what I wanted, I just thought I'd ask in case there was a way I'd overlooked to replace the built-in commands.  It looks like all you'd need to do is change the constructor of RichTextBoxCommands from internal to public, but there may be have other implications for you that I haven't considered.

    My aim was to create AnnotationRanges that were similar to ReadOnlyRange, but without all the restrictions.  I want to be able to select and format text as with non-readonly text, but just prevent changing their values (which I've done by cancelling commands that would result in changes via OnCommandExecuting).
  5. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 27 Nov 2014 Link to this post

    Hello Charles,

    The only suitable approach at this moment is the one you already found out. Working with RadDocumentEditor.

    When it comes to restricting the Insert and Delete commands, subscribing to command executing event and canceling the commands in question, is the right way to do it.

    Regards,
    Mihail
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top