c# - Command parameter passing parent reference -
i have wpf treeview , need reference of parent node in child node context. menu command. in below xaml, need pass reference of in member command parameter
xaml:
<datatemplate x:key="member"> <textblock text="{binding}" tag="{binding datacontext, relativesource={relativesource ancestortype=mylib:extendedtreeview}}"> <textblock.contextmenu> <contextmenu> <menuitem header="delete" command="{binding relativesource={relativesource ancestortype=contextmenu}, path=placementtarget.tag.deletemmebercommand}"> <menuitem.commandparameter> <multibinding converter="{staticresource mutilvalueconverter}"> <binding path=".."/> <binding /> </multibinding> </menuitem.commandparameter> </menuitem> </contextmenu> </textblock.contextmenu> </textblock> </datatemplate> <hierarchicaldatatemplate datatype="{x:type a}" itemssource="{binding members}" itemtemplate="{staticresource member}" <textblock text="{binding"}> <textblock.contextmenu> <contextmenu> <menuitem header="delete" command="{binding relativesource={relativesource ancestortype=contextmenu}, path=placementtarget.tag.deleteacommand}" commandparameter="{binding}"/> </contextmenu> </textblock.contextmenu> </textblock> </hierarchicaldatatemplate> <treeview itemssource="{binding as}"/>
converter:
public class mutilvalueconverter : imultivalueconverter { public object convert(object[] values, type targettype, object parameter, cultureinfo culture) { return values; } public object[] convertback(object value, type[] targettypes, object parameter, cultureinfo culture) { throw new notimplementedexception(); } }
if understand correctly, possibly invert whole thing:
publish command in datacontext , give instance of subdatacontext command parameter (this binding items)
Comments
Post a Comment