Creating screens

Topics: UI Architecture
Oct 24, 2011 at 11:42 AM

I have a screen that displays a list of ViewModels. Clicking a button in one of the views for these VMs should open a new screen related to it (kind of master-details, but both are opening in the same conductor).

I am unsure what mechanism to use to open the new screen. I can think of 3 ways:

  1. EventAggregator - doesn't seem "right" as this isn't an event, it's a command.
  2. Use a command object - how do I get a reference to the conductor to add the new screen?
  3. Call method directly on the conductor - how do I get a reference to the conductor? I would need to pass it to each VM

What is the correct approach?

Thanks,

Jon

Nov 1, 2011 at 2:32 PM

Let me expand a bit. I have a TabControl, one tab has a list of items. Clicking a button on one of the items should open another tab with the details of that item. What is the best approach for doing this in an MVVM way with Caliburn?

Thanks,

Jon

Nov 1, 2011 at 3:54 PM
Edited Nov 1, 2011 at 3:55 PM

the example for windows phone, with respect to HelloWP7 (code reference only, nothing to do with the platform), this example has a tabitem(s) that are created based on the number passed to the Func, you should be able to something similar, in silverlight or wpf.   just remember you don't actually create ICommands (thank you CM) to do it.

As for implimentation, trap for the SelectionChange (CM short hand way or Interactivity + CM your choice) on the ListBox and use navigationservice to navigate() the appropriate viewmodel with the integer corresponding to the record that you want the viewmodel to create a tab for..  Style the tabitem so that it can be closeable.

 

Morgan.

Nov 2, 2011 at 6:07 PM

I'm using WPF with a view model first approach. I've looked at the SimpleMDI example, and that has the conductor creating and activating the tabs, which makes sense. I want to open a tab from view model inside another tab (the view model is part of a hierarchy of other view models). Should I pass the conductor to the view model, so I can call a method on it from the child view model?