Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TypeConverter.ConvertFrom Method (ITypeDescriptorContext, CultureInfo, Object)

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
)

Parameters

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

Return Value

Type: System.Object
The converted value.

ExceptionCondition
NotImplementedException

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 Silverlight 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 null or 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, then 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.

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.

Community Additions

Show:
© 2014 Microsoft