Prevent command from executing when different tool is selected

4 posts, 0 answers
  1. Frank
    Frank avatar
    31 posts
    Member since:
    May 2006

    Posted 14 Jan 2019 Link to this post

    Hi,

    I noticed that some commands get executed/ changes saved when selecting a different tool.

    For instance:

    1. Seleting the tool to insert text
    2. Selecting forms

    The text is placed inside the image. This is pretty annoying if the user accidently clicked on it. Is there a way to persist this changes only when a user has clicked a custom button?

     

    Best regards

  2. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    657 posts

    Posted 17 Jan 2019 Link to this post

    Hello Frank,

    What I can suggest in order to achieve the desired requirement is handling the ToolCommitted event of the RadImageEditor and executing an Undo action when the current tool is the DrawTextTool. Here is some sample code:
    private void ImageEditor_ToolCommitted(object sender, ToolCommittedEventArgs e)
            {
                if (e.Tool.ToString() == "Telerik.Windows.Media.Imaging.Tools.DrawTextTool")
                {
                    this.ImageEditorUI.ImageEditor.Undo();
                }
            }

    In order to persist changes on a button click, you can use the CommitTool method of the RadImageEditor. You can raise a boolean flag in your button click event which you can check inside the ToolCommited event in order to make sure not to Undo the commit when it is invoked through the button. Please, give this approach a try and let me know how it goes.

    Hope you find this helpful.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Frank
    Frank avatar
    31 posts
    Member since:
    May 2006

    Posted 18 Jan 2019 in reply to Vladimir Stoyanov Link to this post

    Hi Vladimir,

    I tried to add the EventHandler to my control, but the ImageEditor is null.

    I'm working with "Demos - Telerik UI for WPF" my code is from the sample "Image Editor | ImageEditor". The only thing I did till now was removing XAML Code from Tools I don't use. So the root is still RadImageEditorUI.

    That is the code I tried:

    ImageEditorUI.ImageEditor.ToolCommitted += ImageEditor_ToolCommitted;

    after initialization ImageEditor is still null.

    Best Regards

  4. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    657 posts

    Posted 22 Jan 2019 Link to this post

    Hello Frank,

    Thank you for the update. 

    I tested the described behavior on my end and I was able to reproduce it only when the RadImageEditorUI was not loaded. May I ask you to make sure that the control is loaded before hooking up the event handler?

    I am attaching a sample project demonstrating the approach for your reference. Please, note that I have used the ToolCommited event instead of the ToolCommiting one.

    Hope this helps. Let me know if I can be of any further assistance.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top