c# - Vertical Grouping - WPF DataGrid or ListView -
how can have below view using wpf or creating custom control?
as need use data templates , cell values might object instances, cannot use winforms use old structure. (not mention if wouldn't!)
grouping level can 1 (like picture) or more. 4 steps satisfactory here.
any other solutions appreciated.
here go
i defined itemscontrol bound items (your data) , defined group style show data expectation.
<itemscontrol itemssource="{binding items}"> <itemscontrol.groupstyle> <groupstyle> <groupstyle.containerstyle> <style targettype="{x:type groupitem}"> <setter property="template"> <setter.value> <controltemplate targettype="{x:type groupitem}"> <grid> <grid.columndefinitions> <columndefinition width="auto" /> <columndefinition /> </grid.columndefinitions> <border borderbrush="black" borderthickness=".5" padding="4"> <textblock text="{binding name}" verticalalignment="center" /> </border> <itemspresenter grid.column="1" /> </grid> </controltemplate> </setter.value> </setter> </style> </groupstyle.containerstyle> </groupstyle> </itemscontrol.groupstyle> <itemscontrol.itemtemplate> <datatemplate> <border borderbrush="black" borderthickness=".5" padding="4"> <textblock text="{binding data}" /> </border> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol>
here code prepare groups
items = new observablecollection<item>(); items.add(new item() { key = "abcd", data = 1 }); items.add(new item() { key = "abcd", data = 2 }); items.add(new item() { key = "qwer", data = 1 }); items.add(new item() { key = "qwer", data = 2 }); collectionview view = (collectionview)collectionviewsource.getdefaultview(items); propertygroupdescription groupdescription = new propertygroupdescription("key"); view.groupdescriptions.add(groupdescription);
after leave wpf , enjoy power of styling , binding
multilevel grouping
to achieve miltilevel grouping need add propertygroupdescription view.groupdescriptions
eg
groupdescription = new propertygroupdescription("key2"); view.groupdescriptions.add(groupdescription);
there no limit of sub group can create, need key group.
Comments
Post a Comment