Caliburn Micro: "children" VM in the main shell of VM

I start with Caliburn.micro and I'm a little confused. Let's say I have a user interface with 2 panels, for example. (this is a fake sample) ClientView and CustomerView and 2 corresponding VMs, CustomerViewModel and CustomerViewModel.

Now, let's say I want to include both panels in the main shell, which should have access to all data elements of type VM, for example:

public class MainViewModel { private CustomerViewModel _vmCustomer; private CustomersViewModel _vmCustomers; ... } 

How viewmodels are created by CM, how can I connect my main shell to each instance of them? Or is this the wrong approach? I don’t need a conductor in its canonical sense, because I don’t activate or deactivate the set of panels, as in MDI: I have an SDI interface with some panels, each of which is supported by its virtual machine, and the main shell that should manipulate them. What is the correct approach in such a scenario?

+4
source share
2 answers

In your MainView.xaml, add two ContentControls and give them names that match the names of the two properties representing your ViewModels.

ViewModel:

 public CustomerViewModel CustomerViewModel { get; set; } public CustomersViewModel CustomersViewModel { get; set; } 

View:

 <ContentControl x:Name="CustomerViewModel" /> <ContentControl x:Name="CustomersViewModel" /> 
+5
source

Another way to do this is

 public CustomerViewModel Customer { get; set; } 

and

 <myApp:CustomerView cal:View.Model="{Binding Customer}/> 

This gives the reader a better idea of what to expect from the presentation . Mixing could also be better.

+2
source

All Articles