Featured post
.net - Invoke a ContextMenu to open -
i need google maps (but in wpf
):
- when
rightclick
on map have contextmenu. - when
rightdoubleclicking
have unzoom action.
so, apparently, little difficult in wpf... after struggling , searching lot, read people compains "we can't predict future" (i ask myself how google predict it), decided "wait" systeminformation.doubleclicktime , display contextmenu.
surely, not ideal, human-observable, don't know other method.
so, problem have following code (i have custom canvas):
contextmenueventargs lastcontextmenueventargs = null; bool? lastcontextmenueventargshandled = null; protected override void oncontextmenuopening(contextmenueventargs e) { lastcontextmenueventargs = e; lastcontextmenueventargshandled = e.handled; e.handled = true; //base.oncontextmenuopening(e); } bool rightmouseclickedonce = false; protected override void onpreviewmouserightbuttonup(mousebuttoneventargs e) { //base.onpreviewmouserightbuttonup(e); console.writeline(">>>>>>>>>>> onpreviewmouserightbuttonup"); if (!rightmouseclickedonce) { rightmouseclickedonce = true; thread thread = new thread( new system.threading.threadstart( delegate() { thread.sleep(system.windows.forms.systeminformation.doubleclicktime); this.dispatcher.invoke( system.windows.threading.dispatcherpriority.background, new action( delegate() { if (rightmouseclickedonce) { console.writeline(">>>>>>>>>>> right click"); rightmouseclickedonce = false; base.onpreviewmouserightbuttonup(e); if (lastcontextmenueventargshandled.hasvalue) { console.writeline(">>>>>>>>>>> lastcontextmenueventargshandled"); lastcontextmenueventargs.handled = lastcontextmenueventargshandled.value; base.oncontextmenuopening(lastcontextmenueventargs); lastcontextmenueventargshandled = null; } //if (this.contextmenu != null) //{ // this.contextmenu.placementtarget = this; // this.contextmenu.isopen = true; //} } } )); } )); thread.start(); } else if (rightmouseclickedonce) { console.writeline(">>>>>>>>>>> right double click"); rightmouseclickedonce = false; base.onpreviewmouserightbuttonup(e); this.onmouserightdoubleclick(e); } }
everything works great little problem: base.oncontextmenuopening(lastcontextmenueventargs);
not seem work...
i set before
if (this.contextmenu != null) { this.contextmenu.placementtarget = this; this.contextmenu.isopen = true; }
and worked, blocks child contextmenu elements opening, , open parent (canvas) contextmenu.
can invoke contextmenu event?
i don't know wpf, can show menu, say, pixel away cursor , see if user right-clicks again in same spot , in system double click time? i've used similar technique once in game , performed nice enough.
menu "fade in" (optionally, out, too) animation make better.
- Get link
- X
- Other Apps
Comments
Post a Comment