开发者

Multidimensional Binding in WPF ListView

开发者 https://www.devze.com 2023-04-07 20:22 出处:网络
I have the fo开发者_StackOverflowllowing Data-Structure: class XItem { public string Name {get;set;}

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消