c# - In Button Click Context Menu How do I bind to viewModel? -


i have button on click on button opening context menu, clicking on context menus binded viewmodel. not happening.

<button content="copy" tag="{binding linkviewmodel, relativesource={relativesource mode=self}}" command="{binding linkcopycommand, updatesourcetrigger=propertychanged}" >     <button.contextmenu>         <contextmenu>            <menuitem header="copy download link " command="{binding path=parent.placementtarget.tag.copyviewcommand, relativesource={relativesource mode=findancestor, ancestortype=contextmenu}}" />            <menuitem ... />         </contextmenu>     </button.contextmenu>  </button> 

i have tried tag property seems me not working. viewmodel working fine if bind button itself, contextmenu databinding not working.

edit:

now code working after discussion, think post here.

what changes made put updatesourcetrigger="propertychanged" here code

<button content="copy" tag="{binding linkviewmodel, relativesource={relativesource mode=self}}" command="{binding linkcopycommand, updatesourcetrigger=propertychanged}" >     <button.contextmenu>        <contextmenu width="{binding relativesource={relativesource self}}">           <menuitem header="copy view link " command="{binding copyviewcommand, updatesourcetrigger=propertychanged}" />           <menuitem ... />        </contextmenu>     </button.contextmenu>  </button> 

however don't know how come works, has work tag property in case of button context menu. if put light think many people me new wpf , data binding benefited.

<button content="copy" command="{binding linkcopycommand, updatesourcetrigger=propertychanged}" > <button.contextmenu>     <contextmenu>        <menuitem header="copy download link " command="{binding path=copyviewcommand}" />        <menuitem ... />     </contextmenu> </button.contextmenu>  

copyviewcommand bound directly datacontext... viewmodel..


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -