WPF left-click Popup Action menu, and Disable right-click menu

Source: Internet
Author: User

In the current version of WPF, many of the controls have a ContextMenu property that can set the component's right-click menu, which is really handy, but sometimes we may need to click the left mouse button to eject the ContextMenu, Instead of right-clicking (that is, when the right mouse button is clicked, the ContextMenu does not pop up), we can easily implement the effect of setting a pop-up menu like in Flex.

1. Add a button with a menu at the front desk, as follows:

<ButtonName= "Btnmenu"Width= " the"Height= "+"Content= "Menu"Initialized= "Btnmenu_initialized">    <Button. ContextMenu>        <ContextMenuName= "ContextMenu">            <MenuItemHeader= "Copy"/>            <MenuItemHeader= "Paste"/>            <MenuItemHeader= "Cut"/>            <MenuItemHeader= "Delete"/>        </ContextMenu>    </Button.contextmenu></Button>

2, in the background, the implementation of initialized= "btnmenu_initialized", initialize the right-click menu is null:

Private void btnmenu_initialized (object  sender, EventArgs e) {     // Set the right-click menu to NULL this     null;}

3. Click the left mouse button pop-up menu, as follows:

Private void Btnmenu_click (object  sender, RoutedEventArgs e) {    // target     This  This . Btnmenu;     // location    this. contextmenu.placement = placementmode.top;     // Show Menu     This true ;}

WPF left-click Popup Action menu, and Disable right-click menu

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.