WPF background Dynamic Build right-click menu

Source: Internet
Author: User

 #regionLoop-Generated right-click menuPrivateContextMenu Contextmenus (dictionary<string, routedeventhandler>list) {ContextMenu cm=NewContextMenu (); Style style= (Style) This. FindResource ("ContextMenu");//Define foreground display templatesCm. Style =style; foreach(vardcinchlist) {MenuItem Menu=NewMenuItem (); Menu. Style= (Style) This. FindResource ("Jjxymenuitem"); Menu. Header=DC.                    Key; Menu. Click+=DC.                    Value; Cm.                Items.Add (menu); }                        returncm; }         #endregion

Where to use the right-click menu:

dictionary<string, Routedeventhandler> dist =Newdictionary<string, routedeventhandler>(); //Add a right-click menu item, including name and eventDist. ADD ("Add", Add_click); Dist. ADD ("Modify", Edit_click); Dist. ADD ("Delete", Del_click); Dist. ADD ("Export", Putout_click); Dgrid. ContextMenu= Contextmenus (dist);

Add the Dgrid to the DataGrid instance object, use the dictionary, string as the menu name, and Routedeventhandler as the menu event.

WPF background Dynamic Build 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.