GenericListXamlContentPrivateSetter Sample

Back to summary

Source

using System.Collections.Generic;
using System.ComponentModel;

namespace XmlSerializersTest.Samples
{
    public class GenericListXamlContentPrivateSetter
    {
        public GenericListXamlContentPrivateSetter()
        {
            Strings = new List<string> {"foo", "bar", "baz"};
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public List<string> Strings { get; private set; } 
    }
}

XAML Serializer

<GenericListXamlContentPrivateSetter xmlns="clr-namespace:XmlSerializersTest.Samples;assembly=XmlSerializersTest" xmlns:s="clr-namespace:System;assembly=mscorlib">
  <GenericListXamlContentPrivateSetter.Strings>
    <s:String>foo</s:String>
    <s:String>bar</s:String>
    <s:String>baz</s:String>
  </GenericListXamlContentPrivateSetter.Strings>
</GenericListXamlContentPrivateSetter>

Deserialization failed:

System.Windows.Markup.XamlParseException: property 'GenericListXamlContentPrivateSetter.Strings' cannot be set because it does not have an accessible set accessor. Line '2' Position '4'.
   at System.Windows.Markup.XamlReaderHelper.Read(XamlNode& xamlNode)
   at System.Windows.Markup.XamlParser.ReadXaml(Boolean singleRecordMode)
   at System.Windows.Markup.TreeBuilderXamlTranslator._Parse()
   at System.Windows.Markup.XamlParser.Parse()
   at System.Windows.Markup.XamlTreeBuilder.ParseFragment()
   at System.Windows.Markup.TreeBuilder.Parse()
   at System.Windows.Markup.XamlReader.XmlTreeBuildDefault(ParserContext pc, XmlReader reader, Boolean wrapWithMarkupCompatReader, XamlParseMode parseMode, Boolean etwTracingEnabled)
   at System.Windows.Markup.XamlReader.Load(XmlReader reader)
   at XmlSerializersTest.Serializers.XamlSerializer.Deserialize(XmlReader reader, Type typeToDeserialize) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\Serializers\XamlSerializer.cs:line 18
   at XmlSerializersTest.SampleProcessor.DeserializeFromString(String xml, IXmlSerializer serializer, Type typeToDeserialize) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\SampleProcessor.cs:line 198
   at XmlSerializersTest.SampleProcessor.RecordDeserializationResults(String xml, IXmlSerializer serializer, Type typeToDeserialize) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\SampleProcessor.cs:line 181