Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would look at using an MVVM framework such as <a href="http://caliburnmicro.codeplex.com/" rel="nofollow">Caliburn.Micro</a> which makes view composition incredibly easy. If you have a property on your view model which is a view model type, and a <code>ContentControl</code> on your view which is named the same as your property, then Caliburn.Micro will locate that view models corresponding view via conventions, do the binding for you automatically, and inject the view into the <code>ContentControl</code>.</p> <p>I would also avoid using dependency properties on your view models, and instead implement <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx" rel="nofollow">INotifyPropertyChanged</a>. Caliburn.Micro comes with a <code>PropertyChangedBase</code> type which implements this interface, and also provides a helper method for invoking the <code>PropertyChanged</code> event using lambda expressions rather than magic strings (which is much better for refactoring later).</p> <p><strong>EDIT</strong></p> <p><a href="http://msdn.microsoft.com/en-us/library/ms743695.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms743695.aspx</a> shows an example of implementing INotifyPropertyChanged.</p> <p>To achieve what you want to do in Caliburn.Micro, you would do something like the following (a crude example, but it shows you how easy it is doing view composition using an MVVM framework):</p> <pre><code>public class MainViewModel : Conductor&lt;IScreen&gt;.Collection.OneActive { private UsersViewModel usersViewModel; private MessagesViewModel messagesViewModel; public UsersViewModel UsersViewModel { get { return this.usersViewModel; } set { this.usersViewModel = value; this.NotifyOfPropertyChanged(() =&gt; this.UsersViewModel); } public MessagesViewModel MessagesViewModel { get { return this.messagesViewModel; } set { this.messagesViewModel = value; this.NotifyOfPropertyChanged(() =&gt; this.MessagesViewModel); } public MainViewModel() { this.UsersViewModel = new UsersViewModel(); this.MessagesViewModel = new MessagesViewModel(); this.Items.Add(this.UsersViewModel); this.Items.Add(this.MessagesViewModel); // set default view this.ActivateItem(this.UsersViewModel); } public ShowUsers() { this.ActivateItem(this.UsersViewModel); } public ShowMessages() { this.ActivateItem(this.MessagesViewModel); } } </code></pre> <p>Note that <code>UsersViewModel</code> and <code>MessagesViewModel</code> would derive from <code>Screen</code>.</p> <p>To invoke the <code>ShowUsers</code> or <code>ShowMessages</code> verbs with Caliburn.Micro, you just need to create view controls with the same name. The conductor type has an <code>ActiveItem</code> property which is the currently conducted item, so you can add a <code>ContentControl</code> to your MainView.xaml which is named <code>ActiveItem</code>, and Caliburn.Micro will take care of injecting the correct view. </p> <p>So your MainView.xaml may look like:</p> <pre><code>&lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="200" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinition&gt; &lt;!-- Menu in left hand column --&gt; &lt;StackPanel Grid.Column="0"&gt; &lt;Button x:Name="ShowUsers"&gt;Show Users&lt;/Button&gt; &lt;Button x:Name="ShowMessages"&gt;Show Messages&lt;/Button&gt; &lt;/StackPanel&gt; &lt;!-- Currently active item --&gt; &lt;ContentControl x:Name="ActiveItem" Grid.Column="1" /&gt; &lt;/Grid&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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