xaml - How can I bind a ContextMenu inside a DataTemplate to the DataContext of the parent ListBox -
i have contextmenu (from silverlight toolkit) inside datatemplate used itemtemplate of listbox:
<datatemplate x:key="billitemdatatemplate"> <grid margin="0,0,0,12" x:name="itemgrid"> <kit:contextmenuservice.contextmenu> <kit:contextmenu> <kit:menuitem header="delete item" command="{binding ???????.deleteitemcommand}" commandparameter="{binding}" /> </kit:contextmenu> </kit:contextmenuservice.contextmenu> [...] </grid> </datatemplate>
how can tell contextmenu.command bind property on view-model exposed outer datacontext (i.e. 1 applies listbox)? if i'm right, cannot use wpf relative declarations explained here.
i prefer if child view-models wouldn't require reference "parent" view-model.
use can use elementname bindings. don't have code here can like
datacontext="{binding elementname=layoutroot,path=datacontext}"
where layoutroot element outside listbox, or listbox itself.
Comments
Post a Comment