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