Hiding root menu items

Topics: CAB & Smart Client Software Factory
Apr 19, 2007 at 3:53 PM
I know how to hide command-related things such as toolbar buttons and menu items, but how can I hide non-command-related menu items? For instance if I have a menu File and want to hide it - how do I do that? I don't really want to hide File, but just using it as an example.
Apr 20, 2007 at 5:39 PM
You need to maintain a reference to the button or menuitem after it is created, since you are talking about manipulating an object that you can't manipulate through the command interface.

I suggest storing menuitems in a service once they are created, so you can retrieve them and manipulate their state whenever and wherever necessary.

Apr 25, 2007 at 2:07 PM
We took an approach of making our menu items hide/show themselves automatically based on the state of their children. In the presenter for the view that contains the menu strip, we subscribe to the added/removed/visible/etc events of the menu strip and menu items.

When a menu item's visible state changes, we look at all of the children of its parent -- if the parent has no visible children, then it becomes invisible as well.

We use this same method to manage separators -- as a menu item is made visible/invisible, we look at the items that are its peers and ensure that the visible items don't begin/end with a separator or have to visible separators next to each other.