简体   繁体   中英

Dynamically creating groups in WPF ListView

I am looking for some help in dynamically creating groups in a WPF listview. In WinForm I would do the following to create the group:

ListViewGroup Group1 = new ListViewGroup();
myListView.Groups.Add(Group1);
ListViewGroup Group2 = new ListViewGroup();
myListView.Groups.Add(Group2);

and this would create the groups. I can then do the following to add items to the groups:

myListView.Items.Add(new ListViewItem("Some String1", Group1))
myListView.Items.Add(new ListViewItem("Some String2", Group2))

In WPF I have searched but could not find a way to do this. Is it possible? I have already created the list view using the following:

<ListView Name="myWPFListView" Grid.Column="1" Margin="9,61,0,20" Grid.Row="0" HorizontalAlignment="Left" Width="252" >
        <ListView.View>
            <GridView>
                <GridViewColumn Header="myHeader" Width="252"/>
            </GridView>
        </ListView.View>
    </ListView>

from here I don't know how to proceed as I would like to create the groups from another class.
Thanks for the help.

您需要使用数据绑定和数据模板来绑定数据, 将对您有所帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM