How to write TypeConvert

Discussion in 'ASP .Net Building Controls' started by Shimon Sim, Jul 29, 2005.

  1. Shimon Sim

    Shimon Sim Guest

    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.
     
    Shimon Sim, Jul 29, 2005
    #1
    1. Advertising

  2. Shimon Sim

    Teemu Keiski Guest

    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




    "Shimon Sim" <> wrote in message
    news:%...
    >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.
    >
     
    Teemu Keiski, Aug 7, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shimon Sim

    How to write TypeConvert

    Shimon Sim, Jul 29, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    452
    Teemu Keiski
    Aug 7, 2005
  2. =?Utf-8?B?QWJlbCBDaGFu?=
    Replies:
    6
    Views:
    9,383
    Rahul
    May 3, 2006
  3. Peter Hansen
    Replies:
    1
    Views:
    393
    Joona I Palaste
    Aug 24, 2003
  4. JasBascom
    Replies:
    1
    Views:
    368
    John Harrison
    Feb 24, 2004
  5. Peter Hansen
    Replies:
    1
    Views:
    419
    Joona I Palaste
    Aug 24, 2003
Loading...

Share This Page