TypeConverter.ConvertFrom Method (ITypeDescriptorContext, CultureInfo, Object)
Converts from the specified value to the intended conversion type of the converter.
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.Object
The value to convert to the type of this converter.
Return ValueType: System.Object
The converted value.
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.
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.