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