User Control and Persistence

User Control and Persistence

Post by Jeff Gaine » Thu, 09 Nov 2006 02:11:03



I have written a User Control based on a ListView, it uses 'extended'
Column Headers, ListViewItems and ListViewSubItems all based on their
respective base classes. In addition it has its own collection class for
the items, sub-items and column headers.

It works exactly as required when I use it in a project with links to the
source files but when I try to use the compiled DLL it forgets its column
header settings from design mode to run mode.

I am (at least half) guessing this is related to Persistence but since
that's a new subject to me I need a bit more help than I can find in the
help file - i.e. an example would be good!

Am I on the right lines? If so can anybody point me to an example or
tutorial on Persistence? If I'm on the wrong track any other
thoughts/suggestions?

Many thanks.

--
Jeff Gaines
 
 
 

User Control and Persistence

Post by Jeff Gaine » Thu, 09 Nov 2006 19:59:02

On 08/11/2006 in message <PBpF# XXXX@XXXXX.COM > Linda



Hi Linda,
Many thanks for your reply, carefully saved :-)

I added the following to my code:

[Category("Behavior"),
Description("The list's column headers."),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor(typeof(CollectionEditor), typeof(UITypeEditor)) ]
public new ExtendedLVColumnHeaderCollection Columns
{
get { return this.m_Columns; }
}

And it's working fine now, I need to study the help and see exactly why -
I guess it's the DesignerSerializationVisibility part that's doing the work?

--
Jeff Gaines

 
 
 

User Control and Persistence

Post by v-lli » Fri, 10 Nov 2006 22:09:50

Hi Jeff,

Thank you for your prompt response.

Yes, you're right. It works because a
DesignerSerializationVisibilityAttribute with a value of Content is
augmented to the collection property in your project.

When a serializer persists the persistable state of a design mode document,
it often adds code to the initialization method of components to persist
values of properties that have been set at design time. This happens by
default for most basic types, if no attribute has been set to direct other
behavior.

With the DesignerSerializationVisibilityAttribute, you can indicate whether
the value for a property is Visible, and should be persisted in
initialization code, Hidden, and should not be persisted in initialization
code, or consists of Content, which should have initialization code
generated for each public, not hidden property of the object assigned to
the property.

Members that do not have a DesignerSerializationVisibilityAttribute will be
treated as though they have a DesignerSerializationVisibilityAttribute with
a value of Visible. The values of a property marked as Visible will be
serialized, if possible, by a serializer for the type. Note that not all
types has such a serializer, e.g. a derived class from CollectionBase, the
ExtendedLVColumnHeaderCollection in your project and etc. For the
properties of these types, we could apply a
DesignerSerializationVisibilityAttribute with a value of Content. Then, the
properties will be serialized in code.

When we apply a DesignerSerializationVisibilityAttribute with a value of
Content to a property, we could also specify custom serialization using the
DesignerSerializerAttribute.

The sample I sent to you in my first reply is the one that implement a
custom serialization.

Hope this helps.
If you have any question, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support