I’m using a value converter which needs to get a list of types, which is a property of the converter. If I would use list of double values, I could use the following syntax (which is working as expected):
Code
public class MyConverter : IValueConverter
{
public List<double> MyList { get; set; }
// ...
}
XAML
<Converter:MyConverter x:Key="MyConverter">
<Converter:MyConverter.MyList>
<System.Double>1</System.Double>
<System.Double>2</System.Double>
</Converter:MyConverter.MyList>
</Converter:MyConverter>
But if I try to use this approach with a list of types, an exception is thrown:
Object of type 'System.RuntimeType' cannot be converted to type 'System.Collections.Generic.List`1[System.Type]'
This is my converter and its usage:
Code
public class MyConverter : IValueConverter
{
public List<Type> MyList { get; set; }
// ...
}
XAML
<Converter:MyConverter x:Key="MyConverter">
<Converter:MyConverter.MyList>
<x:Type TypeName="MyType1" />
<x:Type TypeName="MyType2" />
</Converter:MyConverter.MyList>
</Converter:MyConverter>
I guess the XAML syntax is wrong but I can’t find the right syntax.
Seems like bug in the XAML designer. The given bellow code worked for me. I can build and run application. But In the designer R# hightlights two lines with System:Type and the designer crashes with next two errors per line:
As far as you can see, the difference is in the declaration. You have to use System.Type rather than x:Type.
and the code as a sample
As I was said, this happens because Type class is abstract.
Hope it helps