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

Prevent command from executing when different tool is selected

3 Answers 41 Views
ImageEditor
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 14 Jan 2019, 02:27 PM

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

3 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 17 Jan 2019, 12:50 PM
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.
0
Frank
Top achievements
Rank 1
answered on 18 Jan 2019, 08:15 AM

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

0
Vladimir Stoyanov
Telerik team
answered on 22 Jan 2019, 02:00 PM
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.
Tags
ImageEditor
Asked by
Frank
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Frank
Top achievements
Rank 1
Share this question
or