Any example of changing menus and supporting closing for an 'AllActive' tabbed application?

Topics: Actions & Coroutines, Getting Started, UI Architecture
Jul 1, 2012 at 10:54 PM

I'm a CM newbie and trying to get my head around CM. I am building an application where each tab allows the user different functionality for accessing a server where the active work in all tabs (if any is active) could be running async to each other so the shell is an "Conductor<IScreen>.Collection.AllActive" which I hope was the correct choice. I am looking for suggestions or an sample in two areas -

1. I would like to have the main shell own the application menu and the tab control, and to change the  application menuitems depending on the tab selected and then have the menuitem clicks routed to the respective VM for the tab.

2. Since all tabs could potentially be doing active work simultaneously, I am hoping for an example of how the VM on each tab can participate in helping to decide (via dialogs to the user) if the application can be closed if the close menuitem or the application X icon is clicked. Or if the close should be cancelled per the user response (e.g. they say 'no' since there are unsaved files).

Any examples and suggestions much appreciated.

Thanks, Dave

Jul 2, 2012 at 4:33 PM

Well I have the closing stuff working well (after getting some more sleep and overriding CanClose in the Shell VM) but could use still some suggestions on changing menus in the shell when I switch from tab to tab changing viewmodels where the menus need to be context sensitive.

One approach I'm thinking of is to bind the main menu and supply a whole new menu set when a tab changes but I'm unclear on how to attach a "cal:Message.Attach" property with an action to a MenuItem control. Then I guess the ShellViewModel would publish a message to the TabXXXViewModel to handle the MenuItem click.

Advice on any other approach appreciated.

- Dave

Jul 3, 2012 at 5:04 AM

Would love some idea here on how to best compose menuitems in the shell from the VM. I especially can't figure out how to create the menus in code and attach the VM actions to them. Thanks, Dave

Jul 3, 2012 at 9:55 PM
Edited Jul 3, 2012 at 10:40 PM

Can anyone throw me some rope? I promise to not hang myself with it. Some ideas I can try? A best practice?

There is nothing in the doc or articles I've read that talks about how to compose an application with a top level menu where the menuitems are context sensitive to the different ViewModel on each tab. I'm not sure where to start with this.

Do it all in code (do I just use regular events and not use CM for this) or should I try to do in xaml and VM code somehow and get CM to wire them up?

Jul 4, 2012 at 8:54 AM

If you are using a Conductor OneActive, to conduct your tabs, you can react to the ActiveItem changed event and modify the menu view model as you need, I suppose.

Jul 4, 2012 at 6:45 PM

Is this any help?

Jul 5, 2012 at 6:02 AM

Thx jradxl - interesting as I did not know the search would bubble up but I think no help as my Menu is in the ShellView which also owns the TabControl bound to Items which are the ViewModels used for the tab contents that I have added to the ShellViewModel Items collection. So when clicking a MenuItem, I can't find a ViewModel parent that can handle the click.

Jul 5, 2012 at 6:26 AM
Edited Jul 5, 2012 at 6:29 AM

@Bladewise thx - I was thinking about that approach or alternatively, I was considering binding the MenuItem IsVisible to a Visible property in the ShellViewModel, but in either case, the only way I can think of to handle Message.Attach would be in the ShellViewModel, and would then have to publish each MenuItem click to all the tab viewmodels, where each of them would have to check to see if they were the active item. I guess the MenuItem guard methods would reach down into the active viewmodel.

A second approach I'm using right now is to also put a tab specific menu in each tab viewmodel but that looks kinda weird to have a common app level menu as well as another custom menu in the tab. It works though and was easy to wire up and will keep that until I can figure out or someone can suggest a more elegant looking arrangement that I can easily wire up with CM.

Is this not a fairly common scenario where the app menu changes when changing views? Seems there must be an easier way for CM to this wire up. Maybe I need to somehow rearrange my overall ShellView. I'm not terribly great at UI so please suggest a different approach to where I can better work with CM and somehow have context sensitive menus show depending which tab I am on as well as run an action in the active viewmodel. All of the CM samples I've read don't much do anything with menus.

- Dave