c# - Bind Header of WPF ContextMenu -


i had problem treeview-binding , contextmenu here: selected treeviewitem null

now i'm having problem: have contextmenu

<treeview.contextmenu>     <contextmenu x:name="mycontext" itemssource="{binding occontext}" displaymemberpath="text"/> </treeview.contextmenu> 

http://i.stack.imgur.com/4ga1l.png

(the image shows how contextmenu looks like, don't mind tabitem...).

as can see, it's contetmenu, no menuitem! if user clicks on close, want in viewmodel (raise command?). i'd know button/menu clicked. amount of menus dynamically, since it's itemssource being binded.

this viewmodel:

private observablecollection<t_antwort> _occontext; public observablecollection<t_antwort> occontext {         {         if (_occontext == null)             _occontext = new observablecollection<t_antwort>();         return _occontext;     }     set     {         _occontext = value;         raisepropertychanged(() => occontext);     } } 

so want bind contextmenu (the "items" close , closeotherthankthis) viewmodel, when user clicks on 1 of them, want access them in viewmodel. means don't want bind them 1 one, want somehow event (contextmenuitemclicked (?)) being called , use in viewmodel.

btw. using menuitem under contextmenu create "menu folder", be

" " -> close

" " -> closeotherthankthis

and don't want this.

edit: i'm getting item this:

    private void mycontext_previewmousedown(object sender, mousebuttoneventargs e)     {         system.windows.controls.primitives.menubase s = sender system.windows.controls.primitives.menubase;         itemcollection ic = s.items;         t_antwort selecteditem = (t_antwort)ic.currentitem;     } 

is there possibility selected item binding?

don't know if have tried it, there's placementtarget context menu, gives object contains context menu.

in 1 project had, made this:

 <menuitem ...    visibility="{binding relativesource={relativesource mode=findancestor,ancestortype={x:type contextmenu}},path=placementtarget.selecteditem 

Comments