I've created a context menu within ToolbarManager containing several buttons. I set the Tag property for a toolbar button within Visual Studio Designer to a string that I want to get in the ToolClick event handler so I do like this:
private void OnToolClick(object sender, ToolClickEventArgs e){ switch (e.Tool.Key) { case "New": string s=e.Tool.Tag as string; break; }}
But this string is always null. If I explicitely get the 'New'-button from the ToolbarManager and get the Tag from it it is working correctly:
private void OnToolClick(object sender, ToolClickEventArgs e){ switch (e.Tool.Key) { case "New": ToolBase toolBase = ToolbarsManager.Tools["New"]; string s=toolBase.Tag as string; break; }}
I verified the Key-property and in both cases it is the toolbar button with the same Key. I also ran a loop to output all tools of ToolbarsManager to see if I have two buttons with same Key but that's not the case. When I output the Hashcode of both objects I get different hashcodes so it seems to me that the Toolbase object in ToolClickEventArgs is a different one to that I get from ToolbarsManager.
I also tried if it is has something to do with that I'm using this button in a context menu which is some kind of dynamically created but even when I add this toolbar button into the toolbar it seems to be a different object.
Is the toolbar button object kind of copied when the event is fired? If this is the case what is the reason and why is the Tag property not copied.
Regards, Wolfgang
Hello Wolfgang,
I tried this and it always works fine for me so I attached my sample to this post for you. This also could have something to do with the 'SharedProps' and 'InstanceProps', you could read about them at the following links: http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinToolbars.v11.2~Infragistics.Win.UltraWinToolbars.ToolBase~SharedProps.html
http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinToolbars.v11.2~Infragistics.Win.UltraWinToolbars.InstanceProps.html. Please review the sample and feel free to let me know if I misunderstood you or if you have any other questions.