我一直在互联网上搜索很多来解决这个问题,但找不到合适的解决方案。这就是问题所在:(这是一个 WPF 应用程序,在 VS2010 中)假设我有这个类:
public class Airplane
{
public string AirplaneName{get;set;}
public ObservableCollection<People> myPeopleList {get;set;}
}
public class People
{
public string Name{get;set;}
public string SeatNumber{get;set;}
}
现在我想创建一个 Airplane 类的实例,包括文件 App.xaml 中的人员列表。也就是创建自己的资源(Application.Resources)。我试过了,但我得到了一个例外:
<lcl:AirPlaneCollection x:Key="apCollection" >
<lcl:Airplane Name="airbus-780" myPeopleList="{StaticResource pList}" >
</lcl:AirPlaneCollection>
<lcl:PeopleCollection x:Key="pList">
<lcl:People Name="name1" SeatNumber="1"/>
<lcl:People Name="name2" SeatNumber="2"/>
</lcl:PeopleCollection>
AirPlaneCollection 和 PeopleCollection 只是一个简单的类,它继承自ObservableCollection<Airplane>
并且ObservableCollection<Poeple>
当我尝试使用该资源时 (Application.Current.Resources["appCollection"] 它编译但我在运行时遇到异常。我的 TreeView DataTemplate 表现良好,因为如果我实例化代码隐藏中的类作为常规列表(添加等)它完美地工作..我做错了什么??提前感谢..