I have a custom class using ExpandableObject Converter for code serialization
in design time. When I use this class as a property (get) in a component, the
property changes in the property browser serialized correctly in the
components code (InitializeComponent method) and the changes are persisted.
No problem with that. BUT! While component is in design view, the changes to
the properties of my class does not undo, even it shows the changes in the
undo list of VS.IDE.
Note: I dont want my class to be structure. I know it would work correctly ,
if I used a structure instead of a class and a fully implemented
typeconverter for it. I want it to be a class and it should be read only(
only get accessor implemented) property, when used in a component.
Example:
[TypeConverter(typeof(ExpandableObjectConverter))]
public class UndoClass
{
int _x =0;
int _y =0;
[DefaultValue(0)]
public int X
{
get{ return _x;}
set{ _x = value;}
}
[DefaultValue(0)]
public int Y
{
get{ return _y;}
set{ _y = value;}
}
}
I use the class as component property in a component:
public class MyComponent : System.ComponentModel.Component
{
....
....
UndoClass _undoClass = new UndoClass();
[DesignerSerializationVisibility(
DesignerSerializationVisibility.Content)]
[Browsable( true)]
public UndoClass UndoClass
{
get{ return _undoClass;}
}
}
In the first instance, designer does not show the property in the property
browser. Because of this, I need to inherit my component again to show my
UndoClass property in the property browser:
public class UndoComponent : MyComponent
{
.....
.....
}
Now, make changes to UndoClass property in UndoComponent "design view". You
will see those changes in the undo list of the idee. But when you undo
them(in design view), nothing will happen. Can anyone help me? What can I do
to make undo and redo to work.
Please note, using PropertyDescriptor.SetValue or
DesignerHost.CreateTransaction doesn't help. Because, the changes are being
made in the properties window directly.
THANKS
|