Export (0) Print
Expand All

TypeConverterAttribute Class

Specifies the class to use as a type converter for the type or property that this attribute is bound to.

System.Object
  System.Attribute
    System.ComponentModel.TypeConverterAttribute

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

'Declaration
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.All, Inherited := True)> _
Public NotInheritable Class TypeConverterAttribute _
	Inherits Attribute

The TypeConverterAttribute type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360TypeConverterAttributeInitializes a new instance of the TypeConverterAttribute class.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360TypeConverterAttribute(String)Initializes a new instance of the TypeConverterAttribute class, using the specified type name as the data converter for the object this attribute is bound to.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360TypeConverterAttribute(Type)Initializes a new instance of the TypeConverterAttribute class, using the specified type as the data converter for the object this attribute is bound to.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360ConverterTypeNameGets the fully qualified type name of the type to use as a converter for the object this attribute is bound to.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360EqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)

In Silverlight for Windows Phone, this member is overridden by Equals(Object).


In XNA Framework, this member is overridden by Equals(Object).
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)

In Silverlight for Windows Phone, this member is overridden by GetHashCode.


In XNA Framework, this member is overridden by GetHashCode.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The class you use for type conversion must derive from TypeConverter. Use the ConverterTypeName property to get the name of the class that provides the data conversion for the type or member this attribute is bound to.

The most common use of TypeConverter in Silverlight is to provide the processing for setting XAML attributes and generating object values, both for Silverlight classes and custom classes. You then use TypeConverterAttribute to mark a type or member so that the XAML parser can call the TypeConverter implementation as part of its attribute value processing. For more information, see TypeConverters and XAML.

When you use TypeConverterAttribute to mark a type or member, you can either use a string that names the type (must be fully qualified) or a Type to identify the type converter. If you use Type, you generally include a typeof() within the construction behavior of the attribute.

A TypeConverterAttribute is primarily used for two cases: marking a custom class that is used as the property type of one or more custom properties, or marking individual custom properties. Marking individual custom properties gives you the option of using some existing type for your property type, even if that type does not have attribute usage (or any XAML usage at all) as part of its characteristics. So long as that type is constructible by some means, you can use whatever string input is passed to your type converter in order to determine the construction specifics, then return the object to the property.

Not all Silverlight types use type converter classes as noted by TypeConverterAttribute. In some cases, there is type conversion behavior that is native. If you need access to converted values, you might need to use XAML parsing behavior to access the native conversion. See Using XamlReader.Load.

To apply a property-specific type converter behavior to a custom attached property, apply TypeConverterAttribute to the method that serves as the Get accessor in the implementation pattern for the attached property. For more information, see Custom Attached Properties.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft