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

RadDiagram HowTo add shape into UndoRedoStack after editing a custom property of the shape

2 Answers 60 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Timon
Top achievements
Rank 1
Timon asked on 03 May 2017, 01:56 PM

Hello everybody,

I have a RaDiagram which will be filled via MVVM.

Additionally my shapes and connections have custom properties - for the sake of convenience let's say every shape has a status property.

I customized the SettingsPane, so when entering a shape's SettingsPane I have a checkbox which changes the status property of the shape.
Checked -> shape.status = 1
Unchecked -> shape.status = 0

This is working fine.

Additionally I have a flag in my ViewModel which will be updated after the status change, so that my CanExecuteUndoCommand will set

1.e.CanExecute = True
2.e.Handled = True

 

Unfortunately the UndoRedoStack of the diagram tells me that there is nothing in the stack.
I guess that the UndoCommand (and of course the RedoCommand) only handles the default "Content" property of a shape.

Can you give me an example how I can extend your functionality, to the RadDiagram, that changing custom properties of a shape also fill the UndoRedoStack.

Thanks in advance,
Timon

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 08 May 2017, 10:51 AM
Hello Timon,

To achieve your requirement you can use the UndoableDelegateCommand class and the diagram's UndoRedoService. Here is an example in code:
UndoRedoService service = diagram.ServiceLocator.GetService<IUndoRedoService>() as UndoRedoService;
UndoableDelegateCommand undoableCommand = new UndoableDelegateCommand("CheckCommand",
    (o) => {
        // set the new status
    },
    (o) => {
        // set the previous status
    });
service.ExecuteCommand(undoableCommand);
The last two arguments passed to the constructor of the command class are the action that is currently executed and the undo action.

I hope this helps.

Regards,
Martin
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Timon
Top achievements
Rank 1
answered on 09 May 2017, 07:11 AM
Hi Martin,

Thank you for your response. I managed to implement it and it's working.

Regards
Timon

Tags
Diagram
Asked by
Timon
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Timon
Top achievements
Rank 1
Share this question
or