Suppose that I have a property MyProperty
of type MyType
in a class MyClass
. I want to use XAML to assign it some complex value of another type (let's take String
, for example). So, I create MyTypeConverter
which can convert from String
to MyType
and apply [TypeConverter(typeof(MyTypeConverter))]
to the MyClass
class.
The following code works fine (i.e. invokes MyTypeConverter.ConvertFrom):
<MyClass.MyProperty>
text
</MyClass.MyProperty>
But as soon as I change the property value to a XAML elemet, the TypeConverter is no longer being invoked which results in a conversion exception.
<MyClass.Property>
<sys:String>text</sys:String>
</MyClass.Property>
How can I implement conversion for the values defined as XAML elements?