SerializableGraphSourceBase and undo

2 posts, 0 answers
  1. Rajkumar
    Rajkumar avatar
    9 posts
    Member since:
    May 2014

    Posted 05 Sep 2014 Link to this post

    I derived out my class based on SerializableGraphSourceBase.

    When I add shape to diagram using AddNode, and I try to undo, the shape still exists on the diagram.

    How do i specify so as to consider the AddNode action for undo redo ?
  2. Milena
    Admin
    Milena avatar
    201 posts

    Posted 08 Sep 2014 Link to this post

    Hi Rajkumar,

    When using GraphSourceBase and add a shape through AddNode(), before performing the undo method 
    you should notify the diagram for that action and update the Undo/RedoStack of the RadDiagram. You can achieve this by using UndoRedoService and UndoableDelegateCommand like so: 

    private void AddShape (...)
    {
         ....
       graphSource.AddNode(newShape);
     
       UndoableDelegateCommand addShape = new UndoableDelegateCommand(CommandNames.AddShape,
        c =>
        {
            graphSource.AddNode(newShape);
        },
        c =>
        {
            graphSource.RemoveItem(newShape);
        });

       this.diagram.UndoRedoService.AddCommand(addShape);           
    }

    You can notice that I've used:
    - static class CommandNames for the name of the UndoableDelegateCommand and 
    - AddNode() and RemoveItem() which comes from SerializableGraphSourceBase. 
    This will allow you to take advantage of the built-in Undo/Redo functionality of the diagram and just register the new action.

    For your convenience I implemented this approach in the attached project. Please take a look at it and let us know if it works for you.

    Regards,
    Milena
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top