xaml - DataBinding to a context menu in wpf? -


i have usercontrol, defined so:

<usercontrol x:name=usercontrolname>        <usercontrol.resources>               <style targettype="{x:type mycontrol}">             <setter property="contextmenu">                 <setter.value>                     <contextmenu >                         <menuitem header="item"                                   command="{binding elementname=usercontrolname, path=deletecommand">                                                   </menuitem>                     </contextmenu>                 </setter.value>             </setter>             <setter property="template">                 <setter.value>                     <controltemplate targettype="{x:type controltype}">                                                 <grid>                                                         <!--mycontenthere-->                         </grid>                     </controltemplate>                 </setter.value>             </setter>                 </style>          </usercontrol.resources>      <grid>        <!--content -->        <listbox>         <listboxitem> <!--is of type mycontrol-->        </listbox>     </grid> </usercontrol> 

this not work, usercontrolname's datacontext not being found.

am missing here?

you should try using wpf relativesource binding such:

 <contextmenu >     <menuitem header="item"           command="{binding relativesource={relativesource ancestortype={x:type usercontrol}}, path=datacontext.deletecommand}">                               </menuitem> </contextmenu> 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -