Class ValueSourceTypeConverter
A type converter for converting strings to ValueSource or ValueSource<T>.
public class ValueSourceTypeConverter : TypeConverter
- Inheritance
-
ValueSourceTypeConverter
- Inherited Members
Remarks
This type converter only supports converting from string, for use by the XAML parser.
The text can either be a literal value or an expression surrounded by square brackets ([
, ]
).
To specify a literal value that starts with [
but that is not an expression, prefix the value with %
. For example, for a literal string value of "[literal]", use %[literal]
.
To specify a constant null value, do not use "{x:Null}"
, which will set the ValueSource or ValueSource<T> property itself to null.
Instead, use "[null]"
; the type converter will optimize the result for the property type.
For ValueSource<T> types, this type converter requires context to be provided to CanConvertFrom(ITypeDescriptorContext, Type), with a IProvideValueTarget service available /// that provides a PropertyInfo value via TargetProperty. When loading workflows from XAML, this is automatically provided.
Methods
CanConvertFrom(ITypeDescriptorContext, Type)
Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
Parameters
context
ITypeDescriptorContextAn ITypeDescriptorContext that provides a format context.
sourceType
TypeA Type that represents the type you want to convert from.
Returns
ConvertFrom(ITypeDescriptorContext, CultureInfo, object)
Converts the given object to the type of this converter, using the specified context and culture information.
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
Parameters
context
ITypeDescriptorContextAn ITypeDescriptorContext that provides a format context.
culture
CultureInfoThe CultureInfo to use as the current culture.
value
objectThe object to convert.
Returns
Exceptions
- NotSupportedException
The conversion cannot be performed.
- Exception
value
is not a valid expression text value. (The specific exception thrown varies depending on the expression value type.)