wpf - Binding from context menu item to parent control -


i have control, on control command called savetoclipboardcommand. want bind context menu item command command when click it, copy clipboard command executed.

<control x:name="control">     <control.contextmenu>         <contextmenu>             <menuitem command={"bind savetoclipboardcommand here"} header="some header" />         </contextmenu>     </control.contextmenu/> </control> 

the control (for argument sake) defined this:

partial class control {       private icommand _savetoclipboard;       public icommand savetoclipboardcommand       {                     {               if (_savetoclipboard == null)               {                   _savetoclipboard = new relaycommand(                          x=> savetoclipboard());               }               return _savetoclipboard;           }      } } 

i have tried using relativesource , elementname based bindings both failing. trying possible?

thanks!

edit (after showing how control exposed): contextmenu tricky, because it's not part of same visual tree. try doing this:

<menuitem command="{binding path=placementtarget.savetoclipboardcommand,     relativesource={relativesource ancestortype=contextmenu}}"/> 

original answer

is command exposed public property of control? if command exposed in viewmodel hanging of control's datacontext, following:

command={binding elementname=control, path=datacontext.savetoclipboardcommand} 

can show how command exposed?


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -