Groups | Blog | Home
all groups > dotnet windows forms designtime > october 2004 >

dotnet windows forms designtime : Undo/redo for DesignOnly properties


draiko NO[at]SPAM rhenus.de
10/7/2004 9:37:43 AM
Hi,

I wrote a component with a DesignOnly property. The property is a custom
dictionary (inheriting from DictionaryBase) that has a TypeConverter
to/from string type. Values are saved into and read from resource file
correctly when the containing form is saved/loaded.

The dictionary can be changed only by a custom editor. It acts as
a "stecialized property page". The editor starts a designer transaction,
calls OnComponentChanging()/OnCo0mponentChanged() and Commit() or
Cancel() at the end.

When OnComponentChanging() is called all properties are serialized for
undo/redo and Cancel(). The dictionary is accessed by
CodeDomSerializer.SerializePropertiesToResources() -- looks fine --
but the type converter of the dictionary is never called.

String properties of the same component (also DesignOnly) are treated
by VS properly: When i undo the last transaction organized by the
editor, they get old values assigned.

VS assignes something to the dictionary property also trying to undo changes,
but this is (a copy of) the same pointer to the dictiionary.
(Even object.ReferenceEquals() says "true".) May be that the pointer was
copied before the changes were done, but it is a pointer to the same
dictionary, that is changed now.

Only when I open the .resx window the converter is called. It is obvoius,
that without knowing how to [de]serialize my objects, VS can not support
undo/redo and only the converter knows how this should be done.

Can someone tell me, what I am doing wrong?

The converter is bound correctly to the property -- serializing and
deserializing into/from .resx prowes this.

Thanks,
draiko NO[at]SPAM rhenus.de
10/12/2004 3:30:37 AM
Hello,

May be interesting not only for me.

It looks like that it is not possible to persist/depersist DesignOnly
properties for undo/redo if they are collections, dictionaries, etc.

Folowing the general serialization rules they must have
DesignerSerializationVisibility.Content.
But CodeDomSerializer.SerializePropertiesToResources() serializes only
those properties that have DesignerSerializationVisibility.Visible
(or nothing, that defaults to Visible). Since both is not possible,
i see no way to serialize DesignOnly collections for und/redo directly.

An additional string-typed property that returns a serializable form
of the collection and creates a background collection when assigned
must be enough. This means, actually, to mimic the serialization
infrastructure.
This does not forbid to have a non-serializable "native" property to
access the "background" collection directly.

Regards,
Dima.

[quoted text, click to view]
AddThis Social Bookmark Button