Caliburn.Micro: Various "goals" in XAML and how to get Views / Viewmodels there

I still consider myself a novice, although I could use CM for good use. I read this nice introduction to screens and guides, etc. From Rob Eisenberg in the code. If I understand correctly, the conductor itself is a screen and can show screens.

However, I donโ€™t see how to start by achieving something like this (very pseudocode):

Xaml

<Grid> <Left x:Name="Menu" /> <Right x:Name="Content/ActiveItem" /> </Grid> 

Now, how can I load two different screens, or maybe wires, to display in these two places?

I tried to understand from the HelloScreens example, but unfortunately it got so many dependencies, I donโ€™t know how to run it. I see that ShellView has two target areas, one of which is the usual " ActiveItem ", the other is called " Dialogs ", but searching for strings in "Dialogs" shows nothing. Too much magic happens at this point in time.

Hence my question. What is the best strategy to finally understand how Views are in XAML and how to achieve something as shown above with Caliburn.micro?

Greetings

+4
source share
1 answer

Caliburn comes with several types of conductors out of the box. One explorer without a set of elements (but ActiveItem) and several explorer with collections of elements and ActiveItem.

Of course, you could also implement your own explorer, but here it does not seem necessary. It sounds like you just want your ShellViewModel be a conductor, perhaps the one with the collection of items it holds makes the most sense, so you can get the ShellViewModel from Conductor<IScreen>.Collection.OneActive .

You donโ€™t need to keep any items on the menu, maybe you just need a link to the Items collection on your ShellViewModel . In your ShellViewModel constructor ShellViewModel you can instantiate each of the view models that appear on the menu (perhaps using an abstract factory would be the most enjoyable way), and then pass the Items link to the MenuViewModel .

Each element that your ShellViewModel can be obtained from Screen , so that they have a normal screen life cycle ( OnActivate , OnDeactivate , etc.). Your MenuViewModel not running and does not require a screen life cycle, so it can simply be inferred from PropertyChangedBase .

With Caliburn.Micro, whenever you have a ContentControl on your view with the same name as a property in your view model, whose value is itself a view model, then Caliburn.Micro will detect this view of view models and add this in ContentControl, and take care of the bindings too.

Thus, your ShellViewModel may have a MainMenu property of type MenuViewModel , and your shell view looks something like this:

 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="200" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> </Grid> <ContentControl x:Name="MainMenu" Grid.Column="0" /> <ContentControl x:Name="ActiveItem" Grid.Column="1" /> 
+4
source

Source: https://habr.com/ru/post/1341528/


All Articles