Save/Load when using MVVM

11 posts, 0 answers
  1. Scott Waye
    Scott Waye avatar
    111 posts
    Member since:
    Nov 2009

    Posted 25 Sep 2012 Link to this post

    Hi,

    When using the MVVM approach and setting the GraphSource property, what is the recommended way to persist the diagram?  The Save method works but Load does not work when GraphSource is set.
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 28 Sep 2012 Link to this post

    Hi Scott,

     Please make sure you use the SerializableGraphSourceBae<TNode, TLink> which inherits from ObservableGraphSourceBase (ensuring the two-way bindings) and suitable for serialization operation.

    All the best,
    Petar Mladenov
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  3. DevCraft banner
  4. Scott Waye
    Scott Waye avatar
    111 posts
    Member since:
    Nov 2009

    Posted 28 Sep 2012 Link to this post

    HI,

    Thanks, Im now inheriting from SerializableGraphSourceBase as suggested.  When I drag a shape from the toolbox onto the canvas I see that it calls DeserializeNode where it attempts to get from the info the value of NodeUniqueIdKey.  However this value is not in the serialization info and an exception is thrown.  I use a subclass of RadDiagramShape so I overrode Serialize in this class and added the info value for "NodeUniqueIdKey" :

        public class BpmnStartShape : RadDiagramShape
        {
            public BpmnStartShape()
            {
                Geometry = App.Current.Resources["bpmnStartShapeGeometry"] as Geometry;
            }

            public override Telerik.Windows.Diagrams.Core.SerializationInfo Serialize()
            {
                var info = base.Serialize();
                info["NodeUniqueIdKey"] = this.Id;
                return info;
            }

    Is that the correct approach ?

    --
    Scott
  5. Scott Waye
    Scott Waye avatar
    111 posts
    Member since:
    Nov 2009

    Posted 28 Sep 2012 Link to this post

    Hi Petar,

    What would really help here is a sample project, do you have one?  When using the SerializableGraphSourceBase, are you still meant to use the Save/Load methods on RadDiagram ?

    Thanks,

    Scott
  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 Oct 2012 Link to this post

    Hello Scott,

     We prepared a sample project for you which we can use in our future discussions on the topic. Is it possible for you to modify it so that your issues are reproducible? Thank you in advance.

    Regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  7. Jose
    Jose avatar
    4 posts
    Member since:
    Sep 2010

    Posted 18 Mar 2015 Link to this post

    Hola Amigo tengo un problema parecido a este al momento de cargar xml en el Diagram pero yo tengo un template Personalizado con un ViewModelNodeCustom al igual que Conecction..
    Vi el XML y tanto en los elemntos Shapes como Conection en el Model me Devuelve el nombre de mi ViewModelCustom Guarda y y me da esto: Project.Test.ViewModels.ViewModelNodeCustom y en los conections esto: Test.ViewModels.ClassLinkViewModel.
    por tanto al hacer el Load en el Diagrama de ese XML el no tiene el objeto ViewModelCustom por tanto no se ve esa clase tiene botones, Controles personalizados, Lista.

    Como podría lograr que el XML lleve todo eso aunque creo eso seria mucho pedir, lo que quiero lograr es que si el usuario mueve de posición los elementos del Diagrama esto cuando cargue se vea tal cual como el usuario lo dejo y ademas que si hay un nuevo elemento lo agregue sin afectar el cambio de posición de los elementos que el usuario a hecho.. 

  8. Jose
    Jose avatar
    4 posts
    Member since:
    Sep 2010

    Posted 18 Mar 2015 Link to this post

    Sorry envie doubt in Spanish ,,,,
    Hello I have a friend like this when the Load method to load an xml in the Diagram, problem but I have a Custom template with ViewModelNodeCustom just like a Conecction.
    I saw both XML and Shapes elemntos as in Model I Conection Returns the name of my ViewModelCustom Save and gives me this: Project.Test.ViewModels.ViewModelNodeCustom and the conections this: Test.ViewModels.ClassLinkViewModel.
    therefore to make the diagram Load XML that he has the ViewModelCustom object therefore is not what I'm drawing I have custom properties that control what is going to draw the command control buttons if any ,, dynamic is what I'm doing,

    As might make the XML bring all that but I think that would be too much to ask, what I want to achieve is that if the user moves to position elements diagram that when loading look as it as user I leave and that if there is a new item to add it without affecting the change in position of the elements that the user moved.
  9. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Mar 2015 Link to this post

    Hi Jose,

    I am afraid I do not understand your requirements completely. Is it possible to send us more details about your scenario ?
    - what you have so far - how is your diagram set up
    - the structure of your ViewModels
    - your Views
    - what actions do you perform on the RadDiagram
    - what are the specific issues you need to resolve
    Please feel free to send us a video or sample project that we can investigate. Thank you in advance for your cooperation.

    Regards,
    Petar Mladenov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Jose
    Jose avatar
    4 posts
    Member since:
    Sep 2010

    Posted 24 Mar 2015 in reply to Petar Mladenov Link to this post

    Good morning .

    I am sending you a simple example where I show what I need , Basically I have two buttons, one to add items Shape Standard and one for Load it from a Node ViewModel Custom you want to see in the demo both cases , the first add items and then store the XML and then upload again, Veras is loaded perfectly in the second do the same , you see that the second is more complex , it has a button that is associated with a Command and works but to save the XML and re- display the XML bring Me the design and perhaps could solve this problem by making a crossing of Diagram Items by reassigning the class because I want to keep the position in which the user leave each item. I hope you can help me.
  11. Jose
    Jose avatar
    4 posts
    Member since:
    Sep 2010

    Posted 24 Mar 2015 in reply to Jose Link to this post

    Sorry that does not happen does not want me to attach the compressed project or Zip or Rar sent him the link to the example from DropBox :
    https://www.dropbox.com/sh/1irg2xtte4tgs19/AABdePgLn2RU-OqPQZKEHcDca?dl=0
    I suggest you use this tool to view the contents of XML http://xmlgrid.net/
  12. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 27 Mar 2015 Link to this post

    Hi Jose,

    For the exception that is reproducible in your project when you add both Shape and NodeViewModel (clicking first 2 buttons) - it is expected and you can reproduce it easily if you use both Items and ItemsSource collection of an ItemsControl - for example ListBox. This is a Framework limitaion for both WPF and Silverlight.

    The other issue - the CircleShape is not properly saved / loaded - it is more complex and requires multiple changes in your code. However, most of them are based on this help article for serializing databound diagram and we highly encourage you to read it completely. I changed your GraphSource to be SerializableGraphSoureBase and added code for Serializing "Titulo" and "Subtitulo"in SerializeNode and DeserializeNode. The I hit an issue that DeserializeNode is not fired in version 729 Q2 2014 SP. The good news is that this isse is resolved in Q1 2015 - the attached project uses this version (our latest official Release). We hope are able to upgrade to this version.

    Regards,
    Petar Mladenov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
DevCraft banner