Hello experts.
I have a class called VisualAspect. This class stores information about
how to draw things (backcolor, forecolor, font, ...). This class is
complete with a TypeConverter (which returns a constructor based
InstanceDescriptor), DefaultValue attributes on every public property,
and ShouldSerializeXXX and ResetXXX methods on properties that cannot
provide constant/integral properties.
This class is used by my user control, which simplistically is laid out
as such:
public class Grid : System.Windows.Forms.UserControl
{
// ctor/ other stuff
VisualAspect normal_aspect = new VisualAspect();
VisualAspect hottrack_aspect = new VisualAspect();
[DesignerSerializationVisibility(Content)] <- shortened, by u get it
public VisualAspect AspectNormal
{ get... set... }
[DesignerSerializationVisibility(Content)]
public VisualAspect AspectHotTrack
{ get... set... }
}
Now, the problem is, the Forms designer won't serialize any modified
properties properly.
Here is a snippet from a form's code that contains my user control.
void InitializeComponent()
{
VisualAspect visualAspect1 = new VisualAspect(); // not necessary-
already constructed !
visualAspect1.BackColor = Color.Red; // ok- I set this in the
property grid
Grid grid1 = new Grid(); // ok
grid1.Location = ... // ok
grid1.Size = ... // ok
// No meaningful assignment is ever made in the code above, because
visualAspect1 goes out of scope.
}
Any thoughts or pointers to a good ComponentModel tutorial would be
appreciated since MSDN docs on this topic are cryptic and incomplete.
Dan I
Can you provide some snippet for your VisualAspect class (is it a Component?
if it is, maybe this is the major cause of the problem)
> void InitializeComponent()
> {
> VisualAspect visualAspect1 = new VisualAspect(); // not necessary-
already constructed !
This is perhaps because of your TypeConverter which returns an
InstanceDescriptor. Do you really need a cutom TypeConverter? Perhaps what
you need is just the ExpandableObjectConverter class...
By the way, you don't need a set counterparts for your VisualAspects
property, you already have an instantiated it in your Grid Class, you only
need to modify its internal properties, making it readonly will suffice,
just like the WinForms Controls (ControlCollection) property.

Signature
Joey Calisay
http://spaces.msn.com/members/joeycalisay/
> Hello experts.
>
[quoted text clipped - 49 lines]
>
> Dan I
dan - 04 Mar 2005 04:51 GMT
Thanks joey.
I screwed around with it more and *just* about got it working.
The only reason I implemented a custom converter was because in the
future, the Grid (or other controls) may expose a collection for
VisualAspect objects- thereby the designer needs an instancedescriptor
to support the collection editor.
I did what you said and made the control's properties read-only- that
did the trick.
No, my VisualAspect class does not derive from component.
The only thing left (which I can live with), is that the PropertyGrid
displays the VisualAspect's string representation in a bold format, even
though *no* properties in the object have been modified.
That's no big deal though. I can learn to live with it.
Thanks for your quick reply- I'll send you a copy (when it is finished)
of a Gantt Chart component I'm working on for .Net.
Dan I