WPF ListView grouping by 2 columns but display only 1 group header -
a listview displays collection of following class:
public class employee { private string _department; private string _manager; private string _name; private string _address; public string department { { return _department; } } public string manager { { return _manager; } } public string name { { return _name; } } public string address { { return _address; } } }
there 1-to-1 relation between department , manager, 2 rows same department have same manager.
i want group department/manager, group header showing "department (manager)".
my collectionviewsource looks like
<collectionviewsource x:key="cvsemployees" source="{binding employees}"> <collectionviewsource.groupdescriptions> <propertygroupdescription propertyname="department" /> <propertygroupdescription propertyname="manager" /> </collectionviewsource.groupdescriptions> </collectionviewsource>
the plan not display first level header (department) , somehow bind both department (1st level) , manager (2nd level) 2nd level header.
3 questions:
to avoid displaying 1st level header, have empty data template in groupstyle:
<groupstyle> <groupstyle.headertemplate> <datatemplate> </datatemplate> </groupstyle.headertemplate> </groupstyle>
this seems clunky. there more elegant way skip group header?
how bind 1st grouping level property (department) 2nd level header (manager) achieve required "department (manager)" ?
is there better way creating 2 grouping level?
thanks
solved main stumbling block, question 2 above: how bind group header property not grouping property.
the solution change data context to:{binding items}
. itemsource properties available
<groupstyle> <groupstyle.headertemplate> <datatemplate> <stackpanel orientation="horizontal" margin="0,10,0,3" datacontext="{binding items}" > <textblock text="{binding path=department}" fontweight="bold" margin="3"/> <textblock text="{binding path=manager, stringformat='({0})'}" margin="3"/> </stackpanel> </datatemplate> </groupstyle.headertemplate> </groupstyle>
Comments
Post a Comment