all groups > asp.net building controls > july 2005 >
You're in the

asp.net building controls

group:

How to write TypeConvert


How to write TypeConvert Shimon Sim
7/29/2005 12:26:37 PM
asp.net building controls:
I am writing a control and need to introduce custom nested property.
I need it to look exactly as XXXStyle properties for DataGrid.
I starting looking into TypeConverters and it seems that I need to override
ConvertTo and ConvertFrom methods. All the examples I saw show some custom
implementation of value - comer separated or semicolon separated values.
I need it to look the way it look in datagrid - xml.
Plus I have complex properties inside - like color and font.
How do I handle all this?

Thank you,
Shimon.

Re: How to write TypeConvert Teemu Keiski
8/7/2005 12:00:00 AM
Hi,

it doesn't need a type converter (it is meant for converting complex object
to string so that it can also be parsed back from markup to represent a
property).

Instead you make the style property read-only, and apply

[NotifyParentProperty(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty)]

attributes to the property.

The style property could look something like this

[NotifyParentProperty(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty)]
public virtual TableItemStyle ItemStyle
{
get
{
if (this.itemStyle == null)
{
this.itemStyle = new TableItemStyle();
if (base.IsTrackingViewState)
{
this.itemStyle.TrackViewState();
}
}
return this.itemStyle;
}
}


--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke




[quoted text, click to view]

AddThis Social Bookmark Button