.NET Framework Class Library for Silverlight
TypeConverterAttribute Class

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

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

Visual Basic (Declaration)
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.All, Inherited := True)> _
Public NotInheritable Class TypeConverterAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As TypeConverterAttribute
C#
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets.All, Inherited = true)]
public sealed class TypeConverterAttribute : Attribute
Remarks

The class you use for conversion must inherit 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. 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.

Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.ComponentModel..::.TypeConverterAttribute
Thread Safety

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

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

See Also

Reference

Other Resources

Tags :


Page view tracker