WPF Button in the left mouse button click popup ContextMenu, allowed to fail right ContextMenu

2010-04-21  来源:本站原创  分类:DotNet  人气:645 

In the current version of WPF, many of the controls have a ContextMenu property, you can set the component's context menu, this really is very convenient, but sometimes we may need to click the left mouse button when it pops up the ContextMenu, rather than right-click (ie: When you click right mouse button does not pop up when the ContextMenu), so we can easily achieve a similar pop-up menu to set Flex effect ...

This is the default context menu:

First:

Then, set this:

<Button Name="btnMenu" Width="50" Height="25" Content=" Menu  " Initialized="btnMenu_Initialized">
            <Button.ContextMenu>
                <ContextMenu Name="contextMenu">
                    <MenuItem Header=" Replication  "/>
                    <MenuItem Header=" Paste  "/>
                    <MenuItem Header=" Cut  "/>
                    <MenuItem Header=" Delete  "/>
                </ContextMenu>
            </Button.ContextMenu>
        </Button>

See Initialized = "btnMenu_Initialized" Implementation:

private void btnMenu_Initialized(object sender, EventArgs e)
        {
            // Set the right-click menu for  null
            this.btnMenu.ContextMenu = null;
        }

Then click the left mouse button to set the pop-up menu:

private void btnMenu_Click(object sender, RoutedEventArgs e)
        {
            // Target
            this.contextMenu.PlacementTarget = this.btnMenu;
            // Location
            this.contextMenu.Placement = PlacementMode.Top;
            // Display the menu
            this.contextMenu.IsOpen = true;
        }

Well, running, click the button, the effect:

For those interested to try Oh!

相关文章
  • WPF Button in the left mouse button click popup ContextMenu, allowed to fail right ContextMenu 2010-04-21

    In the current version of WPF, many of the controls have a ContextMenu property, you can set the component's context menu, this really is very convenient, but sometimes we may need to click the left mouse button when it pops up the ContextMenu, rathe

  • Using the mouse hook into the left mouse button 2011-05-04

    Using the mouse hook into the left mouse button Since the left mouse button to use and more easily damaged, I use the left mouse button to a Microsoft there is a problem, click the left mouse button does not respond. The mouse apart and did not find

  • gdk simulate mouse button events / focus events 2010-02-04

    Reference: http://library.gnome.org/devel/gdk/stable/gdk-Event-Structures.html # GdkEventButton #include <glib.h> #include <gtk/gtk.h> void example (GtkWidget *mainWindow) { GdkEvent *press_event; press_event = gdk_event_new (GDK_BUTTON_PRESS)

  • Save as shield against web right mouse button 2009-07-10

    Sometimes we do hard work out of web pages, others Save As, and suddenly out of one another to imitate the same WEB years, devoted to the log on the "Save as shield against web right" and knowledge of skills, these Dongdong if you to spend, you

  • windows to use the mouse button 2010-07-21

    In the "Control Panel" open "Accessibility Options" in the "mouse" tab select the "Use the mouse 7 key." This allows the keyboard to control the mouse cursor, mouse simulation refers to the keyboard on the right mou

  • ubuntu mouse button paste feature 2010-10-15

    ubuntu mouse button, in fact, is not a problem, ubuntu the mouse button is used to quickly paste, but windows are used to, at times hand to hand winded tap, resulting in a lot of trouble 1, open firefox mouse button scroll function Edit -> First item

  • Flex shield and customize the right mouse button menu (reproduced) 2010-11-08

    Recent projects on hand need to shield the right mouse button menu Flex and the new flex custom mouse right click. By ContextMenu hideBuiltInItems, or reach the effect I want, damn few options still exist, plundered for a long time on the Internet an

  • Mouse button in the browser, the value of the difference 2010-11-27

    We know that a standard mouse with left, center and right three keys. Press the mouse pressed, how to determine which key is it? W3C DOM-Level-2 are defined as follows W3C DOM writes During mouse events caused by the depression or release of a mouse

  • Read jq of seven (to determine which clicks the mouse button) 2010-12-03

    jQuery discard the standard button properties by which, this is a bit confusing. which was introduced in Firefox, IE does not support. which are intended to be for the keyboard keys (keyCode). jQuery in which that can be a keyboard key, the mouse can

  • ubuntu mouse button paste functionality 2010-10-15

    ubuntu mouse button, in fact, is not a problem, ubuntu the middle mouse button is used to quickly paste, but windows are used to, from time to time on hand-winded point about single-handedly, resulting in a lot of trouble 1, open firefox mouse button

  • Howto disable / enable global mouse right click 2011-05-22

    Quote from: http://ubuntuforums.org/showthread.php?t=1401293 Global ban right, the new file / usr / local / bin / mouse_map: #!/bin/bash case $1 in off) /usr/bin/xmodmap -e "pointer = default" /usr/bin/xmodmap -e "keycode 117 = Menu" ;

  • Click a button to block or b button grayed out 2010-10-22

    / / Shield <? Xml version = "1.0" encoding = "utf-8"?> <Mx: Application xmlns: mx = "http://www.adobe.com/2006/mxml" layout = "vertical"> <Mx: Button label = "Button" height = "140"

  • JavaScript control with IE / firefox right mouse button to copy the page view the source code. 2010-03-08

    <body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.e

  • To solve the middle mouse button failures Ubuntu 10.04 2010-04-30

    1. $ Sudo vi etc / etc / hal / fdi / policy / mouse-wheel.fdi If you do not create a new. Here vi can be emacs, geidt any editor, etc. 2. Copy the contents of the following <? Xml version = "1.0" encoding = "UTF-8"?> <match ke

  • Mouse button to zoom image 2010-12-03

    <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN"> <HTML> <HEAD> <TITLE> New Document </ TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author&q

  • [Transfer] as3 classes CustomerContextMenu right mouse button menu 2011-01-07

    http://hi.baidu.com/xinhua0228/blog/item/094e363b3bb147e215cecb86.html package { import flash.events.ContextMenuEvent; import flash.ui.ContextMenu; import flash.ui.ContextMenuBuiltInItems; import flash.ui.ContextMenuItem; /** * ... * @author liuxh */

  • failure of the left mouse button under the old ubuntu 2011-05-13

    Occur after 10.10 upgrade to old problem, there are some solutions online, but many of the link failure, could not make the patch, but then I found that when I turn off firefox, after a few seconds can not move, such as how long to do with whether wi

  • html: cancel button in the role, cancel button, cancel button 2011-07-24

    struts tags to determine html: cancel html: cancel tag to generate a cancel button. When you click the button corresponding action servlet to bypass the form bean validate () method, while the control to the appropriate action. The action can be used

  • With the timer delay to achieve the mouse double click event events, click and double-click events independently of each other! 2010-03-29

    import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Date; import java.util.Timer; /** * Use the timer delay click event implements mouse double-click event , Click and double-click event from interfering with each o

  • html: cancel button of the role, cancel button, cancel button 2010-05-06

    Transfer from http://heisetoufa.javaeye.com determine tag struts html: cancel html: cancel tag to generate a Cancel button. When clicking the button will bypass the corresponding action servlet form bean's validate () method, while the control to the