i have following context menu declared in application resources, , referenced several tree views in app. trying send treeview's selecteditem property command parameter.
the problem is can't figure out how commands send treeview's selecteditem.
the parameter null. have tried using relative sources, templated parents, etc.; as, looking target of treeview, treeviewitem, , datacontext. have tried sending different properties of these items (not treeview's selecteditem). can't seem resolve anything.
<application.resources> <contextmenu x:key="contextmenu.treeview"> <menuitem header="add node" command="{binding addnodecommand}" commandparameter="{binding path=selecteditem, relativesource={relativesource ancestortype={x:type treeview}}}"></menuitem> <menuitem header="delete node" command="{binding deletenodecommand}" commandparameter="{binding path=selecteditem,relativesource={relativesource ancestortype={x:type treeview}}}"></menuitem> </contextmenu> </application.resources> <usercontrol ...> <treeview x:name="taxonomytree" itemssource="{binding path=tree}" contextmenu="{staticresource contextmenu.treeview}"/> </usercontrol>
try:
<contextmenu x:key="contextmenu.treeview"> <menuitem command="{binding addnodecommand}" commandparameter="{binding relativesource={relativesource findancestor, ancestortype={x:type contextmenu}}, path=placementtarget.selecteditem}" header="add node" /> <menuitem command="{binding deletenodecommand}" commandparameter="{binding relativesource={relativesource findancestor, ancestortype={x:type contextmenu}}, path=placementtarget.selecteditem}" header="delete node" /> </contextmenu>
contextmenu
not part of same visual tree treeview
links against. need use placementtarget
route treeview
accordingly.
Comments
Post a Comment