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.
Dim strM As String strM = "1,2,3,4" Dim m As New System.Drawing.Printing.Margins(1, 2, 3, 4) Console.WriteLine(TypeDescriptor.GetConverter(strM).CanConvertTo(GetType(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(GetType(BorderAppearanceConverter))> _ Public Class BorderAppearance Private borderSizeValue As Integer = 1 Private borderColorValue As Color = Color.Empty <Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(1)> _ Public Property BorderSize() As Integer Get Return borderSizeValue End Get Set If value < 0 Then Throw New ArgumentOutOfRangeException("BorderSize", value, "must be >= 0") End If If borderSizeValue <> value Then borderSizeValue = value End If End Set End Property <Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(GetType(Color), "")> _ Public Property BorderColor() As Color Get Return borderColorValue End Get Set If value.Equals(Color.Transparent) Then Throw New NotSupportedException("Transparent colors are not supported.") End If If borderColorValue <> value Then borderColorValue = value End If End Set End Property End Class
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: