Featured post
xaml - WPF : How to create separate Resources for each item in a bound ItemsControl -
i want achieve following:
- my viewmodel exposes property named 'categories' collection of categoryviewmodel objects
- each categoryviewmodel object exposes property called 'items' collection of strings*.
- on view, want tabcontrol tabitem each object in 'categories' collection.
the content of each tabitem should xceed datagrid control displaying contents of selected tab's items collection.
<tabcontrol itemssource="{binding categories}"> <tabcontrol.itemtemplate> <datatemplate> <textblock text="{binding categoryname}" /> </datatemplate> </tabcontrol.itemtemplate> <tabcontrol.contenttemplate> <datatemplate> <xcdg:datagridcontrol itemssource="{binding items}" autocreatecolumns="true"> </xcdg:datagridcontrol> </datatemplate> </tabcontrol.contenttemplate> </tabcontrol>
this works ok when bind directly itemssource property of datagridcontrol. however, in order utilize of functionality of datagridcontrol, need bind itemssource property of datagridcontrol datagridcollectionviewsource object bound items collection. when grid isn't nested in control creating datagridcollectionviewsource object in resources section of usercontrol , binding that.
<usercontrol> <usercontrol.resources> <xcdg:datagridcollectionviewsource x:key="griddata" source="{binding items}" /> </usercontrol.resources> <grid> <xcdg:datagridcontrol itemssource="{binding source={staticresource griddata}}" autocreatecolumns="true"> </xcdg:datagridcontrol> </grid> </usercontrol>
how need structure xaml when tabcontrol being bound, datagridcollectionviewsource object created each tabitem datagridcontrol generated within content of tabitem can bound it?
clear mud, right? :)
thanks!
notes:
*in real solution collection contains objects of class more complex simple string, string used make example more simple.
ok, bit of long-shot, use datagrid.tag ...
<tabcontrol.contenttemplate> <datatemplate> <xcdg:datagridcontrol itemssource="{binding relativesource={relativesource self}, path=tag}" autocreatecolumns="true"> <xcdg:datagridcontrol.tag> <xcdg:datagridcollectionviewsource x:key="griddata" source="{binding items}" /> </xcdg:datagridcontrol.tag> </xcdg:datagridcontrol> </datatemplate> </tabcontrol.contenttemplate>
or ... resources can defined on frameworkelement, try:
<tabcontrol.contenttemplate> <datatemplate> <xcdg:datagridcontrol itemssource="{binding source={staticresource griddata}}" autocreatecolumns="true"> <xcdg:datagridcontrol.resources> <xcdg:datagridcollectionviewsource x:key="griddata" source="{binding items}" /> </xcdg:datagridcontrol.resources> </xcdg:datagridcontrol> </datatemplate> </tabcontrol.contenttemplate>
i don't use exceed grid cannot test whether these work - couple of ideas try!
colin e.
- Get link
- X
- Other Apps
Comments
Post a Comment