Persisting design-time property values?

  • Thread starter Thread starter David Veeneman
  • Start date Start date
D

David Veeneman

I'm backporting a component to .NET 1.x, and it required me to use a custom
collection, StringList, instead of List<string>. StringList is derived from
CollectionBase and is marked serializable.

Here's my problem: I can't get design-time property values to persist. Here
is my property declaration:

[Browsable(true)]
[Category("Data")]
[Description("The text to be shown for each link level while in its active
state")]
[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design",
"System.Drawing.Design.UITypeEditor, System.Drawing")]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
[EditorBrowsable(EditorBrowsableState.Always)]
public StringList ActiveTextList
{
get { return p_ActiveTextList; }
set { this.SetActiveTextListProperty(value); }
}

I thought I had the attributes required to serialize the property, but I
guess I'm missing something.

Can anyone shed some light on this? How come my property value isn't
persisting? Thanks.
 
Found my problem. The DesignerSerializationVisibility attribute was set
incorrectly. It should be:

[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]

Note that it is not necessary to implement ISerializable on a custom class
to get it to serialize, unless you want the class to take control of the
serialization process.
 
Back
Top