Multidimensional Binding in WPF ListView
I have the fo开发者_StackOverflowllowing Data-Structure:
class XItem
{
public string Name {get;set;}
public int Position { get;set;}
...
}
class MyItemList
{
public List<XItem> Items{get;set;}
...
}
Now i want to bind a List of MyItemLists to a WPF-ListView. I want to have a ListViewItem for every XItem. But i cannot bind it directly, because the Items-Property is a List of XItems.
Is it possible to realize this without restructuring my Datasource?
thanks
myList.DataSource = myListOfMyItemList.SelectMany(i=>i.Items);
You can use SelectMany of Linq to flatten your list before assigning it to datasource property of list. If you're using MVVM then you can have a property of your ViewModel return a flatten version of the List by using code as mentioned above.
精彩评论