Persisting design-time property values?

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.
 
D

David Veeneman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top