Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>mvvm is not that hard. in your case you need first a mainviewmodel.</p> <pre><code>public class MainViewModel { private ICollectionView _myView {get;set;} public ObservableCollection&lt;MyModulWrapper&gt; MyModules{get;set;} public MyModulWrapper SelectedModul {get;set;} public MainViewModel() { this.MyModules = new ObservableCollection&lt;MyModulWrapper&gt;(); //i use icollectionview because i often need sorting or filtering this._myView = = CollectionViewSource.GetDefaultView(this.MyModules); this._myView .CurrentChanged += (s, e) =&gt; { this.SelectedModul = this._myView .CurrentItem as MyModulWrapper; }; } } </code></pre> <p>you have to fill(in any way - i use mef for my apps, but hardcoded its also ok) your collection with all modules(viewmodels) you wanna show on your top screen. the MyModulWrapper just contain the viewmodel for your modul and a nice display name for your navigation.</p> <pre><code>public class MyModulWrapper { public string Displayname {get;set;} public object Modul {get;set;}//instead of object you can take an interface or base class or whatever } </code></pre> <p>now you have all to let the mainview run :) you just have to set the datacontext for the MainWindow to your MainViewModel.</p> <p>mainwindow.xaml</p> <pre><code> &lt;Window.Resources&gt; &lt;!--for each viewmodel you wanna show create a datatemplate. so wpf knows how to render your viewmodel--&gt; &lt;DataTemplate DataType={x:Type local:MyViewmodel4FirstButton&gt; &lt;local:MyFirstButtonView /&gt; &lt;/DataTemplate&gt; &lt;/Window.Resources&gt; &lt;!-- for navigation --&gt; &lt;ListBox ItemsSource="{Binding MyModules}" SelectedItem="{Binding SelectedModul , Mode=OneWay}" IsSynchronizedWithCurrentItem="true"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Displayname}"/&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;!-- all you need to show your selected modul - if you have a DATATEMPLATEs!! --&gt; &lt;ContentControl Content="{Binding SelectedModul }"/&gt; </code></pre> <p>all your viewmodels have to implement INotifyPropertyChanged of course, and raise it properly.</p> <p>ps: code is written without IDE so ignore errors^^</p>
 

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