TypeConverterAttribute Class
TOC
Collapse the table of content
Expand the table of content

TypeConverterAttribute Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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)

No code example is currently available or this language may not be supported.

The TypeConverterAttribute type exposes the following members.

  NameDescription
Public methodTypeConverterAttribute()Initializes a new instance of the TypeConverterAttribute class.
Public methodTypeConverterAttribute(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 methodTypeConverterAttribute(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 propertyConverterTypeNameGets the fully qualified type name of the type to use as a converter for the object this attribute is bound to.
Top

  NameDescription
Public methodEqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodMatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns 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 is to provide the processing for setting XAML attributes and generating object values, both for Windows Phone 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.

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 Windows Phone 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 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.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

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

Show:
© 2017 Microsoft