Load Custom Graphsource from file without RadDiagram instance

7 posts, 0 answers
  1. Simon
    Simon avatar
    6 posts
    Member since:
    Jan 2017

    Posted 14 Jan Link to this post

    Hello!

     

    My application has a RadTabControl where each tab contains a RadDiagram with a GraphSource-Binding to a view model (TabViewModel).

    At the moment I need to reference the RadDiagram in the TabViewModel for loading and saving reasons, because I found no way to save/load a graphsource to/from filesystem.

    Having a reference to RadDiagram in my view model is not very MVVM like, make problems in our architecture and is not what we want.

    In the end I want to have a single reference to a custom graph source in may TabViewModel which can be loaded by something like graphsource.Load(filepath);

    The .Load on the graphsource should populate the graphsource with items and links from the selected file.

    The same should be possible for the .Save method.

    How could I achieve that?

    Thanks.

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1385 posts

    Posted 18 Jan Link to this post

    Hello Simon,

    RadDiagram doesn't have a built-in mechanism for saving and loading the GraphSource object into a file. To save and load diagram items you can use the serialization feature. However, this is available only in the RadDiagram context and it saves information about the visual elements (shapes and connections). You can save additional properties using the serialization events.

    If you don't want to have a diagram reference in the TabViewModel, you can create custom save and load and load events in the model and raise them when you want to save/load the diagram. For example, RequestSaveEvent and RequestLoadEvent. Then you can subscribe for them in code-behind and call the Save() and Load() methods of the diagram control.

    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.
  3. Simon
    Simon avatar
    6 posts
    Member since:
    Jan 2017

    Posted 19 Jan in reply to Martin Ivanov Link to this post

    That's very frustrating, because that leads to bad design.

    Every tab in the tabcontrol has it's own diagram instance. So there are multiple diagrams in my application. At the moment I have a RadDiagram reference in my tab view model.

    That's what I want to remove, because having a reference to a user interface element in a view model isn't very nice as you know.

    I know about the serialization process of graph source objects you mentioned, but I would like to have a solution where I don't need to have a reference to a diagram instance in code behind. 

    I understand what you mentioned in your last section but it doesn't satisfies my needs. 

    In my understanding that's not what MVVM was made for...

    Are there no other possibilities to get this done?

    Best regards,

    Simon

  4. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1385 posts

    Posted 23 Jan Link to this post

    Hi Simon,

    I agree. Coupling the diagram (the UI) with the view model is not very MVVM-friendly. However, the serialization mechanism of the diagram is designed to work with UI elements and there is no MVVM implementation at this point. There is partial serialization/deserialization data binding support with the SerializationGraphSourceBase class, that kicks-in with some of the built-in diagram behaviors as copy, paste, calling of the Load() and Save() methods, drag and drop from external application, and more. But the methods responsible for this, internally receive their serialization data from the diagram control and its services. So, it won't be very straight forward to use them to manually saved and load the items.

    In order to achieve your requirement you can think of some kind of custom serialization that manually saves the view models. For example you can use the .NET native serialization. Or you can implement custom saving.

    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.
  5. Frank
    Frank avatar
    2 posts
    Member since:
    Aug 2015

    Posted 26 Jun in reply to Martin Ivanov Link to this post

    Hi there,

    is there still no solution für solving this bug?

    Best regards, Frank

  6. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1385 posts

    Posted 29 Jun Link to this post

    Hi Frank,

    The behavior described in this forum is not supported by the diagram. To achieve this you can implement custom serialization of the graph source as mentioned in the previous posts. Or you can use the diagram's built-in serialization feature and use code-behind to save the graph source.

    Regards,
    Martin Ivanov
    Progress Telerik
    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.
  7. Frank
    Frank avatar
    2 posts
    Member since:
    Aug 2015

    Posted 29 Jun Link to this post

    Hi Martin,

    i found this article 'http://docs.telerik.com/devtools/wpf/controls/raddiagram/howto/raddiagrams-serialize-databound-diagram' and we give it a try!

    Best regards, Frank

Back to Top