ExpandableObjectConverter Class
Assembly: System (in system.dll)
This class adds support for properties on an object to the methods and properties provided by TypeConverter. To make a type of property expandable in the PropertyGrid, specify this TypeConverter for standard implementations of GetPropertiesSupported and GetProperties. Mark child properties with the NotifyParentPropertyAttribute to ensure correct behavior in a PropertyGrid control.
Note: |
|---|
| You should never access a type converter directly. Instead, call the appropriate converter by using TypeDescriptor. For more information, see the examples in the TypeConverter base class. |
For more information about type converters, see the TypeConverter base class and How to: Implement a Type Converter.
The following code example converts a variable of type Margins to a string variable.
string strM="1,2,3,4"; System.Drawing.Printing.Margins m= new System.Drawing.Printing.Margins(1,2,3,4); Console.WriteLine(TypeDescriptor.GetConverter(strM).CanConvertTo(typeof(System.Drawing.Printing.Margins))); Console.WriteLine(TypeDescriptor.GetConverter(m).ConvertToString(m));
String strM = "1,2,3,4";
System.Drawing.Printing.Margins m = new System.Drawing.Printing.
Margins(1, 2, 3, 4);
Console.WriteLine(TypeDescriptor.GetConverter(strM).CanConvertTo(
System.Drawing.Printing.Margins.class.ToType()));
Console.WriteLine(TypeDescriptor.GetConverter(m).ConvertToString(m));
The following code example demonstrates how to use the NotifyParentPropertyAttribute and the ExpandableObjectConverter class to create an expandable property on a custom control. This code example is part of a larger example provided for the NotifyParentPropertyAttribute class.
[TypeConverter(typeof(BorderAppearanceConverter))] public class BorderAppearance { private int borderSizeValue = 1; private Color borderColorValue = Color.Empty; [Browsable(true), NotifyParentProperty(true), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(1)] public int BorderSize { get { return borderSizeValue; } set { if (value < 0) { throw new ArgumentOutOfRangeException( "BorderSize", value, "must be >= 0"); } if (borderSizeValue != value) { borderSizeValue = value; } } } [Browsable(true)] [NotifyParentProperty(true)] [EditorBrowsable(EditorBrowsableState.Always)] [DefaultValue(typeof(Color), "")] public Color BorderColor { get { return borderColorValue; } set { if (value.Equals(Color.Transparent)) { throw new NotSupportedException("Transparent colors are not supported."); } if (borderColorValue != value) { borderColorValue = value; } } } }
System.ComponentModel.TypeConverter
System.ComponentModel.ExpandableObjectConverter
Derived Classes
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Note: