Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i can get dynamic menu name form the database, but i don't know to set id for menu because i want to get details based on menu id.
Posted
Updated 28-Jun-11 5:56am
v2

1 solution

This is not about IDs. You problem is creating Menu during run-time out of the database data. Instead of IDs, there is a command of the interface type ICommand added to each menu item individually. See System.Windows.Controls.MenuItem, http://msdn.microsoft.com/en-us/library/system.windows.controls.menuitem.aspx[^].
Pay attention for the properties: Command, CommandParameter, CommandTarget.

Read about using commanding: http://msdn.microsoft.com/en-us/library/ms752308.aspx[^].

As you're looking for auto-generating of the menu, I would suggest you take the simplest approach. Set up only one common command for all menu items! All items are equal. To make them different use the property System.Windows.Controls.MenuItem.Tag to add some data to each item which later will be used for command invocation. I don't know what data structure you will need for the tag, it depends on your data model, but you can devise any data structure you need to process the click in each individual menu item. Pass the value of this tag (type-casted to its real run-type tag) to the command parameter. Use this data item in handling the command.

—SA
 
Share this answer
 
Comments
Abhinav S 28-Jun-11 12:45pm    
Good answer. My 5.
Sergey Alexandrovich Kryukov 28-Jun-11 12:57pm    
Thank you, Abhinav.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900