Serialize ResourceDictionary of RadDiagramShape

5 posts, 0 answers
  1. Alexander
    Alexander avatar
    77 posts
    Member since:
    Apr 2013

    Posted 20 Feb 2014 Link to this post

    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
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 24 Feb 2014 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alexander
    Alexander avatar
    77 posts
    Member since:
    Apr 2013

    Posted 24 Feb 2014 in reply to Petar Mladenov Link to this post

    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
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 27 Feb 2014 Link to this post

    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
  6. Alexander
    Alexander avatar
    77 posts
    Member since:
    Apr 2013

    Posted 27 Feb 2014 in reply to Petar Mladenov Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready