【发布时间】:2016-02-21 23:50:26
【问题描述】:
假设我有一个列表框
<ListBox ItemsSource="{Binding MyList}"/>
我有一个财产:
private List<dynamic> _myList;
public List<dynamic> MyList
{
get { return _myList; }
set
{
if(value==null)return;
_myList = value;
OnPropertyChanged();
}
}
好的,现在我们来回答我的问题: 我有几个类,我将拥有它们的列表,我希望能够在这个 ListBox 中显示它们。
类:
public class A
{
public string S { get; set; }
public int I { get; set; }
}
public class B
{
public int C { get; set; }
public string Name { get; set; }
public string F { get; set; }
}
public class C
{
public int I { get; set; }
public string Name { get; set; }
public string This { get; set; }
public double That { get; set; }
}
填写我的列表
private void FillA()
{
List<A> listA = GetListAFromSomewhere();
MyList = listA;
}
private void FillB()
{
List<B> listb = GetListBFromSomewhere();
MyList = listb;
}
private void FillC()
{
List<C> listC = GetListCFromSomewhere();
MyList = listC;
}
我得到异常
不能隐式转换类型 'System.Collections.Generic.List' 到 'System.Collections.Generic.List'
我尝试过投射,并寻找转换器。但似乎无法弄清楚。
当我更改为List<object> 时也是如此。
this
感谢您的帮助!
【问题讨论】: