我一直在尋找很多在互聯網上來解決這個問題,並找不到像樣的解決方案。這就是問題所在:(這是一個WPF應用程序,在VS2010) 假設我有這個類:將列表綁定到xaml(wpf)中的對象列表屬性(Application.Resources)
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;}
}
現在我想創建包括文件的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運行良好,因爲如果我將代碼隱藏中的類實例化爲常規列表(Add ect。),它的工作原理完美無缺。我在做什麼錯誤? 謝謝高級..
你會得到哪個例外? –
「在'System.Windows.Markup.StaticResourceHolder'上提供值引發異常。」 –