c# - Close Context Menu in WPF -


i've add context menu border in wpf.

<border>   <border.contextmenu>     <contextmenu x:name="historypanelcontextmenu">       <contextmenu.template>         <controltemplate>           <grid background="{binding background}">             <grid.columndefinitions>               <columndefinition></columndefinition>               <columndefinition></columndefinition>             </grid.columndefinitions>             <button grid.column="0" background="transparent" borderbrush="transparent" name="cancelbtn" content="{x:static strings:resource.cancelbtn}" previewmouseup="cancelbtn_onpreviewmouseup" foreground="#fff" fontfamily="segoe ui semibold" fontsize="10">               <button.template>                 <controltemplate targettype="{x:type button}">                   <border x:name="bdr_main" background="transparent" height="36" verticalalignment="top" borderbrush="#c0b6d1" borderthickness="2" cornerradius="2" margin="30,0,15,0">                     <contentpresenter verticalalignment="center" horizontalalignment="center" margin="8,6,8,6" contentsource="content" />                   </border>                   <controltemplate.triggers>                     <trigger property="ismouseover" value="true">                       <setter targetname="bdr_main" property="background" value="transparent"/>                     </trigger>                     <trigger property="ispressed" value="true">                       <setter targetname="bdr_main" property="background" value="#7fc0b6d1"/>                     </trigger>                   </controltemplate.triggers>                 </controltemplate>               </button.template>             </button>             <button grid.column="1" verticalalignment="top" foreground="#fff" background="#ff567e94"  fontsize="10" tag="{binding id}" previewmouseup="uielement_onpreviewmouseup" margin="15,5,0,5" fontfamily="segoe ui semibold" >               <textblock verticalalignment="center">                 <image height="14" width="14" source="/size.wpf;component/assets/icon-trash-white.png" margin="0,0,0,0"/>                 <textblock name="deletebtntext" text="{x:static strings:resource.deletebtntext}"/>               </textblock>               <button.template>                 <controltemplate targettype="{x:type button}">                   <border x:name="bdr_main" height="36" background="#ff567e94" borderbrush="#ff567e94" borderthickness="0" cornerradius="2">                     <contentpresenter verticalalignment="center" horizontalalignment="center" margin="8,6,8,6" contentsource="content" />                   </border>                   <controltemplate.triggers>                     <trigger property="ismouseover" value="true">                       <setter targetname="bdr_main" property="background" value="#ff567e94"/>                     </trigger>                     <trigger property="ispressed" value="true">                       <setter targetname="bdr_main" property="background" value="#6596b1"/>                     </trigger>                   </controltemplate.triggers>                 </controltemplate>               </button.template>             </button>           </grid>         </controltemplate>       </contextmenu.template>     </contextmenu>   </border.contextmenu> </border> 

i tried close context menu on button click. found solution set isopen false. well, tried in next way :

historypanelcontextmenu.isopen = false; 

but historypanelcontextmenu undefined , don't know why.

so how can close context menu on click?

thanks.

did try binding mouse event on context menu ?

<contextmenu x:name="timecardgridcontextmenu" mouseleftbuttonup="dosomething"> 

and use sender or event args access stuff need ?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -