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

Load Custom Graphsource from file without RadDiagram instance

6 Answers 96 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 14 Jan 2017, 07:14 AM

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.

6 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 18 Jan 2017, 02:26 PM
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.
0
Simon
Top achievements
Rank 1
answered on 19 Jan 2017, 06:16 AM

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

0
Martin Ivanov
Telerik team
answered on 23 Jan 2017, 03:00 PM
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.
0
Frank
Top achievements
Rank 1
answered on 26 Jun 2017, 10:17 AM

Hi there,

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

Best regards, Frank

0
Martin Ivanov
Telerik team
answered on 29 Jun 2017, 08:26 AM
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.
0
Frank
Top achievements
Rank 1
answered on 29 Jun 2017, 11:38 AM

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

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