Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Caliburn comes with several types of conductors out of the box. One conductor with no collection of items (but an ActiveItem), and a couple of conductors with collections of items and an ActiveItem.</p> <p>You could of course implement your own conductor too, but that doesn't sound necessary here. It sounds like you just want your <code>ShellViewModel</code> to be a conductor, perhaps one with a collection of items that it is conducting would make the most sense, so you can derive your <code>ShellViewModel</code> from <code>Conductor&lt;IScreen&gt;.Collection.OneActive</code>.</p> <p>You menu doesn't need to conduct any items, it probably just needs a reference to the <code>Items</code> collection on your <code>ShellViewModel</code>. In your <code>ShellViewModel</code> constructor, you could instantiate each of the view models that will appear on the menu (probably using an abstract factory would be the nicest way) and then pass the Items reference to the <code>MenuViewModel</code>. </p> <p>Each item that your <code>ShellViewModel</code> conducts can derive from <code>Screen</code>, so that they have the usual screen lifecycle (<code>OnActivate</code>, <code>OnDeactivate</code> etc). Your <code>MenuViewModel</code> isn't being conducted and doesn't require screen lifecycle, so can just derive from <code>PropertyChangedBase</code>.</p> <p>With Caliburn.Micro, whenever you have a <code>ContentControl</code> on your view with the same name as a property on your view model whose value is itself a view model, then Caliburn.Micro will locate that view models view, and inject it into the ContentControl, and take care of the bindings too.</p> <p>So your <code>ShellViewModel</code> could have a <code>MainMenu</code> property of type <code>MenuViewModel</code>, and your shell view would look something like:</p> <pre><code>&lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="200" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;/Grid&gt; &lt;ContentControl x:Name="MainMenu" Grid.Column="0" /&gt; &lt;ContentControl x:Name="ActiveItem" Grid.Column="1" /&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload