Hi,
I would like to know how it's possible to detect any changes to the image in the editor?
Thank's
Alain
8 Answers, 1 is accepted
You can subscribe to the CurrentImageChanged event of the image history to be notified about changes in the current image.
this
.ImageEditorUI.ImageEditor.History.CurrentImageChanged += History_CurrentImageChanged;
Please note the event is raised when the tool you are working with is committed, i.e. when the image is actually changed. You can also take a look at this SDK example to see how to work with the ToolCommitting and ToolCommitted events.
Regards,
Petya
Telerik
This doesn't actually work. It will only trigger the event when clicking on another ImageToolItem ... it does NOT trigger from when the actual value has changed via manipulation of the slider control for that ImageToolItem.
Oddly "LostFocus" event is always being trigger which actually makes for a better event to process ImageToolItem changes.
Cheers, Rob.
Hello Rob,
Thank you for the LostFocus tip.
The CurrentImageChanged fires when the current image instance is changed. This happens when the currently executing tool is committed. A tool is committed when you click on another tool in the UI, when you click on a button in the settings UI (such button is provided only in few of the tools) or when you manually call the CommitTool() method.
When you change settings via the tool settings UI (like moving sliders, changing texts, drawing shapes, etc.) and the tool is not yet committed, the current image is not changed. Instead an additional layer with elements previewing the applied change is displayed over the current image.
Regards,
Martin Ivanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi Martin,
So if I understand you correctly, there is no way to access the Hue Shift or Saturation values that change until it's committed (other than using my LostFocus approach which is not ideal but works)?
Cheers, Rob.
Hello Robin,
You can access the HueShift and Saturation values before the commit via the Effect property of the corresponding ITool implementation (HueShiftTool and SaturationTool). However, this value won't be applied to the image itself until you commit the executing tool. Also, there is no event that fires when the Effect changes. If you want to listen for changes in the slider's value of the tool, you can create a custom tool deriving from HueShitTool (and another from SaturationTool) and override the GetSettingsUI() method. In the method override, you can get the Grid panel which holds a NumericPropertyEditor in the visual hierarchy, and subscribe to its ValueChanged event.
Regards,
Martin Ivanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello folks,
I have the same problem at the moment and am trying to come up with a solid workaround...
Thanks Rob for the LostFocus approach - good find there.
Using the History.CurrentImageChanged event is OK for some of the image editor controls but as mentioned it doesn't work if you edit the Hue and haven't clicked off the tool to commit it. (It's un-intuitive and a bit clunky to expect end users to clock off a tool to commit it).
I'm trying out the LostFocus method which is nearly there, but this fires if the image is loaded, clicked on, and then the editor loses focus without being edited. This means I'd end up with users potentially being asked "Do you want to save changes" when there aren't any changes.
Overriding the GetSettingsUI method sounds interesting but a very complex way of achieving the goal.
I have raised a feature request here https://feedback.telerik.com/wpf/1505247-image-editor-implement-a-haschanges-property-on-the-image-editor for a HasChanges() property to be added to the Image Editor.
If anyone has any other suggestions on how to achieve some sort of HasChanges() functionality for the image editor I'd love to hear them 👍
Thanks - Richard
Ok I think I am able to move ahead so I'll post what seems to work for me now in case I don't come back to this issue. Hopefully it will help someone else...
The Tools have an IsDirty property that gets set when their effect values change. I found that reading this in the MouseMove event allows you to detect when a value within a tool has been changed.
Here's some pseudo code from the code behind of the view that contains a RadImageEditorUI:
public
bool
HasChanges {
get
;
set
; }
private
void
HistoryOnCurrentImageChanged(
object
sender, EventArgs e)
{
var history = (ImageHistory)sender;
if
(history.CanRedo && !history.CanUndo)
{
HasChanges =
false
;
return
;
}
if
(history.CanRedo || history.CanUndo)
{
HasChanges =
true
;
}
}
private
void
ImageEditor_MouseMove(
object
sender, System.Windows.Input.MouseEventArgs e)
{
if
(ImageEditor.ImageEditor?.ExecutingTool?.IsDirty ??
false
)
{
HasChanges =
true
;
}
}
With the above, HasChanges is set true when a tool has edited the image (flip horizontal for example), or when a tool has been loaded and a value tweaked but not yet committed (resize canvas, change hue etc...).
Hello Richard,
Thank you for sharing your solution. I believe that this is going to be useful for someone else too.
Regards,
Martin Ivanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.