ConvertFrom Method (ITypeDescriptorContext, CultureInfo, Object)
Collapse the table of content
Expand the table of content

TypeConverter.ConvertFrom Method (ITypeDescriptorContext, CultureInfo, Object)

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

Converts from the specified value to the intended conversion type of the converter.

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

public virtual Object ConvertFrom(
	ITypeDescriptorContext context,
	CultureInfo culture,
	Object value


Type: System.ComponentModel.ITypeDescriptorContext
An object that provides a format context.
Type: System.Globalization.CultureInfo
The CultureInfo to use as the current culture.
Type: System.Object
The value to convert to the type of this converter.

Return Value

Type: System.Object
The converted value.


ConvertFrom not implemented in base TypeConverter.

NotImplementedException is thrown by the base implementation and will be surfaced either if an implementation call falls to the base implementation (there was no relevant override) or if you call base deliberately.

Notes to Inheritors

For use as a type converter for custom-type attribute handling in XAML, you should define the ConvertFrom signature with your implementation.

  • Do not rely on information in context, it may be null.

  • Do not throw if context is nullor if culture is null; ConvertFromString calls this signature, passing null for both culture and context.

  • culture when called by the XAML parser is always the en-us culture, so you can assume that behavior if you are writing a TypeConverter that supports XAML parsing. Writing behavior for other culture values might be useful if you intend to support type conversion for scenarios other than XAML support.

  • Always return one of the following: a valid object that is the target conversion type of your converter, or null.

  • Raising exceptions is permissible (unhandled exceptions you throw from a type converter will generate a XamlParseException when the converter is invoked by the XAML parser, possibly with your exception as inner exception).

  • A common practice for a ConvertFrom implementation is to call a relevant class constructor, based on processing any relevant string information found in value into a specific constructor signature.

  • Alternatively, you could call the default constructor and set properties on the created instance before returning it. The call to the constructor is a good way to ensure that the conversion behavior for XAML is well-aligned with the behavior that is used to create an equivalent object in code, and raises the same exceptions if input is invalid.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft