c# - Suppressing right-click context menu on canvas -


i have canvas , when user right clicks on it, context menu appears. have checkbox, , when box checked, don't want context menu appear. reason that, when checkbox checked, first 2 right clicks user drop ellipses @ 2 points of right clicks. right though, context menu popup on 2 right clicks. here's relative code:

<window x:class="testproj.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:local="clr-namespace:testproj"     xmlns:localconverters="clr-namespace:testproj"     x:name="this"     height="650" width="1091"     loaded="this_loaded"     closing="this_closing">      <window.resources>         <local:booltovisibilityconverter x:key="converter"/>     </window.resources>  <grid height="auto">     <grid.resources>         <local:nulltovisibilityconverter x:key="nulltovisibilityconverter" />     </grid.resources>      <grid verticalalignment="top">         <dockpanel>                 <checkbox x:name="scalebox" content="scale" ischecked="false" checked="scaleischecked"/>             </menu>         </dockpanel>     </grid>      <viewbox margin="0,23,0,157" x:name="viewbox1" cliptobounds="true">         <canvas margin="0,21,0,12" x:name="canvas1" cliptobounds="true" renderoptions.bitmapscalingmode="highquality" mousewheel="canvas_zoom" mouserightbuttondown="get_mouseposition"  horizontalalignment="left" width="3138" height="1260">             <canvas.rendertransform>                 <matrixtransform x:name="mt"/>             </canvas.rendertransform>             <canvas.contextmenu>                 <contextmenu name="nodecontextmenu" visibility="{staticresource converter}" >                     <menuitem x:name="test1"  ischeckable="false" header="test1" click="waypointmenuitem_click" >                     </menuitem>                     <menuitem x:name="test2" ischeckable="false" header="test2" click="knownobjectmenuitem_click" >                     </menuitem>                 </contextmenu>             </canvas.contextmenu>         </canvas>     </viewbox> </grid> </window> 

and code behind right-click on canvas:

    private void get_mouseposition(object sender, mousebuttoneventargs e)     {         if (scalebox.ischecked == true)         {             get_points(sender, e);         }     } 

i've tried messing around isopen property of context-menu, open on right click regardless if it's set true or false.

attempt @ converter below. if correct, proper way bind checkbox , contextmenu using this?

namespace testproj { public class booltovisibilityconverter : ivalueconverter {     public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         visibility visibility = visibility.collapsed;         if (value != null)         {             visibility = (bool)value ? visibility.collapsed : visibility.visible;         }          return visibility;     }      public object convertback(object value, type targettype, object parameter, system.globalization.cultureinfo culture)     {         throw new notimplementedexception();     } } } 

i implement valueconverter or multivalueconverter , bind checkbox using converter dictate state (i.e. enabled/disabled) of contextmenu.

        <canvas.contextmenu>             <contextmenu name="contextmenu1" visibility="{binding elementname=scalebox, path=ischecked, converter={staticresource booltovisibilityconverter}}" >                 <menuitem x:name="item1"  ischeckable="false" header="item2" />                 <menuitem x:name="item2" ischeckable="false" header="item1" />             </contextmenu> 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -