Re: AddParsedSubObject and Multiple Identical Property Types
- From: wawang@xxxxxxxxxxxxxxxxxxxx (Walter Wang [MSFT])
- Date: Thu, 01 Mar 2007 10:19:21 GMT
Hi Mark,
The TableItemStyle inherits from Style which associated a TypeConverter.
Here's a simple example on how to create a customized TypeConverter for a
custom property class:
public class MyTypeConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type
destinationType)
{
if (destinationType != typeof(string))
{
throw base.GetConvertToException(value, destinationType);
}
return string.Empty;
}
}
[TypeConverter(typeof(MyTypeConverter))]
public class MyProp2 : IStateManager
{
private string _name;
[NotifyParentProperty(true)]
public string Name
{
get { return _name; }
set { _name = value; }
}
private string _value;
[NotifyParentProperty(true)]
public string Value
{
get { return _value; }
set { _value = value; }
}
#region IStateManager Members
private bool _marked;
bool IStateManager.IsTrackingViewState
{
get { return _marked; }
}
void IStateManager.LoadViewState(object state)
{
if (state != null)
{
Pair p = (Pair)state;
_name = (string)p.First;
_value = (string)p.Second;
}
}
object IStateManager.SaveViewState()
{
return new Pair(_name, _value);
}
void IStateManager.TrackViewState()
{
_marked = true;
}
#endregion
}
public class MyControl2 : CompositeControl
{
private TableItemStyle _firstStyle;
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
]
public TableItemStyle FirstStyle
{
get
{
if (_firstStyle == null)
{
_firstStyle = new TableItemStyle();
if (base.IsTrackingViewState)
{
((IStateManager)_firstStyle).TrackViewState();
}
}
return _firstStyle;
}
}
private MyProp2 _myprop2;
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
]
public MyProp2 MyProp2
{
get
{
if (_myprop2 == null)
{
_myprop2 = new MyProp2();
if (base.IsTrackingViewState)
{
((IStateManager)_myprop2).TrackViewState();
}
}
return _myprop2;
}
}
}
#A Crash Course on ASP.NET Control Development: Building New Controls from
the Ground Up
http://msdn2.microsoft.com/en-us/library/aa479309.aspx
#A Crash Course on ASP.NET Control Development: Building Data-Bound Controls
http://msdn2.microsoft.com/en-us/library/aa479308.aspx
Regards,
Walter Wang (wawang@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Prev by Date: Re: renderbegintag without any tag
- Next by Date: Nested propertiies not set at design time from properties window
- Previous by thread: Re: Programmatically Assign Data Binding Expression?
- Next by thread: Nested propertiies not set at design time from properties window
- Index(es):
Loading