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

Serialize ResourceDictionary of RadDiagramShape

4 Answers 34 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 20 Feb 2014, 08:11 AM
Hi,
I want to serialize (and later deserialize) the content of the ResourceDictionary of the shape.
One Idea was to store the number of resources to serialize and store the dictionary entries as Resource_1, Resource_2, Resource_3, ...
I have to store the Key, the Value and the Type. Is there a convenient (builtin) way to do this? Or have I to convert it manually to a string and back?

Alex

4 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 24 Feb 2014, 12:56 PM
Hi Alexander,

Could you please elaborate a bit more on your scenario ? How do you use this ResourceDictionary ? What does it contain exactly ? 
You serialize a RadDiagramShape with its Serialize() method which will return a SerializationInfo object.
The SerializationInfo has GetString() method which will give you the serialized string.
We hope this can help.

Regards,
Petar Mladenov
Telerik
0
Alexander
Top achievements
Rank 1
answered on 24 Feb 2014, 01:32 PM
Thanks for your answer.
The ContentTemplate of the shape contains some DynamicResources, which are defined globally (as default values) in the app.xaml, but may also be overridden by the user inside the "Resources" property of the shape to customize the appearance. The ResourceDictionary entries may be all kinds of object - like strings, numbers, Brushes, Colors, Fonts, Font Styles, user-defined structs, ...
As these resources are used inside the DataTemplate, the shape cannot know their name or their type when deserializing the content of the ResourceDictionary (so I have to serialize these values, too) - but in the SerializationInfo, only strings are stored, not arbitrary objects.

Alex
0
Petar Mladenov
Telerik team
answered on 27 Feb 2014, 10:02 AM
Hi Alexander,

Thank you for providing more details on your scenario.
I think you can try the following approach. You need to extend the built in serialization in the RadDiagram - this is demonstrated in this help article (section Extending Diagram Serialization). Using this method, you need to serialize the resources of the Shapes. I guess similar scenario is described in various C# / WPF forums , for example this one:
The next step is how to serialize only a particular part of a XAML file - the file which will contain your Shapes.
We believe this could help you get started for this custom requirement.

Regards,
Petar Mladenov
Telerik
0
Alexander
Top achievements
Rank 1
answered on 27 Feb 2014, 02:01 PM
The idea with the XamlWriter sounds promising. Indeed - I only have to serialize the ResourceDictionary (accessible via the Resources property of the Shape), not a part of some xaml file. (the resources to serialize are never stored in any xaml file, as they are set by the user at runtime...)

Alex
Tags
Diagram
Asked by
Alexander
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or