[英]Assign PropertyGroupDescription with a related table column in WPF?
[英]How can I use PropertyGroupDescription with a related table column, when sorting a listbox in WPF?
我想通過相關表格的屬性名稱lightType對列表進行分組。 因此,我嘗試了PropertyGroupDescription“ RelatedPhantoms [0] .lightType.Name”,但似乎找不到該屬性。 我怎樣才能解決這個問題?
ICollectionView view = CollectionViewSource.GetDefaultView(MainLightList.ItemsSource);
view.SortDescriptions.Add(new SortDescription("RelatedPhantoms[0].lightType.Name", ListSortDirection.Ascending));
view.SortDescriptions.Add(new SortDescription("lightSeries.Name", ListSortDirection.Ascending));
view.GroupDescriptions.Add(new PropertyGroupDescription("RelatedPhantoms[0].lightType.Name"));
view.GroupDescriptions.Add(new PropertyGroupDescription("lightSeries.Name"));
以下是支持此燈光集合的數據
public class LightHead : CoreEntity
{
public LightHead()
{
this.RelatedPhantoms = new List<LightHead>();
this.OtherRelatedPhantoms = new List<LightHead>();
}
public LightSeries lightSeries { get; set; }
public Nullable<int> LightSeriesId { get; set; }
public virtual ICollection<LightHead> RelatedPhantoms { get; set; }
public virtual ICollection<LightHead> OtherRelatedPhantoms { get; set; }
}
}
public class LightSeries: CoreModelEntity
{
public string Name { get; set; }
public ICollection<LightHead> lightHeads { get; set; }
public LightType lightType { get; set; }
public Nullable<int> LightTypeId { get; set; }
public LightSeries() { }
public LightSeries(string name)
{
this.Name = name;
}
}
RelatedPhantoms
是一家集LightHead
和lightType
是的屬性LightSeries
因此"RelatedPhantoms[0].lightType.Name"
可能無法正常工作
作為LightHead
類包含lightSeries
類型的屬性LightSeries
其具有屬性lightType
因此您可以將屬性描述更改為
"RelatedPhantoms[0].lightSeries.lightType.Name"
以上是根據看過發布代碼后的一些假設得出的。 您可以根據需要進行調整。
還值得驗證集合RelatedPhantoms的類型為IList<T>
以支持索引器
還驗證是否應該假設RelatedPhantoms
集合的類型為LightHead
或LightSeries
因為確實存在LightSeries
中的lightHeads集合,這使我想到了這些類之間的關系
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.