Which UI element invoked the command

Topics: CAB & Smart Client Software Factory
May 10, 2006 at 3:20 PM
originally posted by: GiriT

Hi,

A MenuItem has been hooked up to invoke a CommandHandler as per the standard way.. however.. How can you get information in the commandhandler about the menuitem itself? Is there anyway to get to the menuitem itself? We want to dynamically create the menu and have all of them invoke the same commandhandler.. in that commandhandler we want to do something different based on which menu was clicked...

Seems like a simple thing to want to do.... And yet the SCSF doesn't seem to provide any mechanism that is obvious....

Thanks
May 11, 2006 at 4:33 PM
originally posted by: DarrelMiller

My understanding is by doing that you are sort of defeating the purpose of the Command infrastructure. The Command has a status that relates to a single command. By handling multiple menu items with the same command handler that command status no longer makes sense.

To do what you want to do then just create an event handler and hook that to the all of the menuitem clicks. In that event check the sender object and do what you want. You can even go get a corresponding Command object and Execute it.

Anyway, just my 2 cents, I'm no authority on the subject.
Oct 19, 2006 at 5:41 AM
originally posted by: Mummas

I found that the "Invoker" (ToolStripMenuItem added via AddInvoker) is buried deep with the Command object in the Invokers collection. It would be a good feature if the SCSF would provide access to the Invoker (ToolStripMenuItem). We can then use the ".Tag" property to do custom handling.

If anyone has figured this out, please publish. Thanks.