Sounds like a bug in the XAML designer. The code below worked for me. I can create and run the application. But in the R # designer, two lines with the System stand out : Type , and the designer crashes with the following two errors in the line:
Error 1 Type "Type" is not used as an element of an object, because it is not public or does not define an open constructor without parameters or type.
Error 2 Type Type does not support direct content. Therefore, when I tried this solution earlier (before giving the previous solution), I thought that I was doing something wrong. But the compiler still does not give any errors during assembly. In any case, what it looks like:
<Window.Resources> <local:Holder x:Key="one"> <local:Holder.Types> <System:Type>System:Int32</System:Type> <System:Type>System:Double</System:Type> </local:Holder.Types> </local:Holder> </Window.Resources> <Grid > <ListBox DataContext="{StaticResource one}" ItemsSource="{Binding Path=Types, Converter={StaticResource one}}" /> </Grid>
As far as you can see, the difference is in the declaration. You should use System.Type, not x: Type.
and the code as a sample
using System; using System.Collections.Generic; using System.Globalization; using System.Windows.Data; using System.Linq; namespace stackProjects { public class Holder : IValueConverter { public List<Type> Types { get; set; } public Holder() { Types=new List<Type>(); } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return Types.Select(x => x.Name).ToList(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }
As I said, this is because the Type class is abstract. Hope this helps.
source share