Binding a nested ListView in WPF -
i have simple listview in have listview. can't seem inner listview bound actual list<>, shows empty.
my code:
public collectionviewsource cvsmain {get;set;} //which list<myclassviewmodel>, main listview bounds correctly public class myclassviewmodel{ public class mysubclass{ public string name{return _name;} } list<mysubclass> mylist = new list<mysubclass>(); public string mytext{get;set;} } my xaml:
<listview datacontext="{binding cvsmain}" itemssource="{binding}" > <listview.view> <gridview> <gridviewcolumn displaymemberbinding="{binding mytext}" header="my text"/> <gridviewcolumn header="my list"> <gridviewcolumn.celltemplate> <datatemplate> <itemscontrol itemssource="{binding mylist}"> <itemscontrol.template> <controltemplate targettype="itemscontrol"> <itemspresenter/> </controltemplate> </itemscontrol.template> <itemscontrol.itemspanel> <itemspaneltemplate> <stackpanel/> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemtemplate> <datatemplate> <listview> <listview.view> <gridview> <gridviewcolumn displaymemberbinding="{binding name}" header="name"/> </gridview> </listview.view> </listview> </stackpanel> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol> </datatemplate> </gridviewcolumn.celltemplate> </gridviewcolumn> if instead of second listview put textblock "{binding name}", works. not sure how bind inner listview, ideas?
thanks,
you have 3 nested controls: outer listview, itemscontrol in middle, , inner listview. think itemscontrol unnecessary. try replacing
<itemscontrol itemssource="{binding mylist}"> ... </itemscontrol> by
<listview itemssource="{binding mylist}"> <listview.view> <gridview> <gridviewcolumn displaymemberbinding="{binding name}" header="name"/> </gridview> </listview.view> </listview> furthermore, change
list<mysubclass> mylist = new list<mysubclass>(); to
public list<mysubclass> mylist { get; set; } because can bind public properties only, not private fields.
Comments
Post a Comment