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

XamlSerializable cant serialize my collection

2 Answers 117 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Christoph
Top achievements
Rank 1
Christoph asked on 17 Apr 2012, 05:17 PM
Hi
In order to add some hidden "meta data" to our RadDocuments
we decided to derive the Section class and add

public class EditorSection : Section
    {
        private ObservableCollection<Metadata> _metadata = new ObservableCollection<Metadata>();
        //[XamlSerializable]
        public ObservableCollection<Metadata> Metadata
        {
            get { return _metadata; }
            set { _metadata = value; }
        }
    }


Now we can create documents in XAML such as:
<c:EditorSection>
<c:EditorSection.Metadata>
 <c:Metadata Name="DocumentId" Value="{00000-..-..-..}" />
 <c:Metadata Name="Owner" Value="JohnWSmith" />
</c:EditorSection.Metadata>
<t:Paragraph>
<t:Span Text="Hi">
</t:Span>
</t:Paragraph>
</c:EditorSection>

However when saving the Document with XamlFormatProvider
the Metadata stuff is removed.

When Debugging my metadata class I can see a two instances
are created and the two props are assigned on load.

When I try an add the [XamlSerializable] attribute to my property
and also to the properties of the MetaData class
I get an runtime XamlParseException on loading the document:
Can't convert object of type "System.String" to "ObservableCollection<MyNameSapce.MetaData>"
The line in question is:

Telerik.Windows.Documents.FormatProviders.Xaml.XamlFormatProvider.Import(String input) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\FormatProviders\Xaml\XamlFormatProvider.cs:Line 126.

So it seems the XamlFormatProvider can't deal with the markup properly.
Is there a way to "tell" the XamlFormatprovider how (de)serialize my meta data collection
Do I need to specify a typeconverter or value converter also?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Mike
Telerik team
answered on 18 Apr 2012, 04:22 PM
Hello Christoph,

We tested the scenario as far as we understand it, and it seems we managed to make it work. I have prepared you a demo that saves/loads Xaml document that contains a custom EditorSection. I think the major issue in your case that the Metadata collection property should be XamlCompositePropertySerializable  instead of XamlSerializable. Please try it out and let us know if you see any issues or if you have other questions.

Kind regards,
Mike
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Christoph
Top achievements
Rank 1
answered on 23 Apr 2012, 03:14 PM
Hi Mike

[XamlCompositePropertySerializable] did the trick.
Thank you so much!

Chris


Tags
RichTextBox
Asked by
Christoph
Top achievements
Rank 1
Answers by
Mike
Telerik team
Christoph
Top achievements
Rank 1
Share this question
or