Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your <code>MainPageViewModel</code> should hold a collection of what pages are in the TabControl, and the SelectedPage. It should also contain an <code>ICommand</code> which will change the current page.</p> <p>For example,</p> <pre><code>// These should be full properties that raise PropertyChange notifications public ObservableCollection&lt;IPageViewModel&gt; Tabs { get; set; } public int SelectedTabIndex { get; set; } private ICommand ChangeTabIndexCommand { get; set; } MainPageViewModel() { Tabs = new ObservableCollection&lt;IPageViewModel&gt;(); Tabs.Add(new Page1ViewModel()); Tabs.Add(new Page2VieWModel()); SelectedTab = 0; ChangeTabIndexCommand = new RelayCommand&lt;int&gt;(ChangeTab); } void ChangeTab(int newIndex) { if (newIndex &gt;= 0 &amp;&amp; newIndex &lt; Tabs.Count()) SelectedTab = newIndex; } </code></pre> <p>Your MainView would look like this:</p> <pre><code>&lt;TabControl ItemsSource="{Binding Tabs}" SelectedIndex="{Binding SelectedIndex}" /&gt; </code></pre> <p>If you are using Silverlight 5, I believe you can use implicit <code>DataTemplates</code>, however if not you'll have to use something like a <code>DataTemplateSelector</code> or a <code>Converter</code> to tell Silverlight how to draw each ViewModel. I usually use <a href="http://msdn.microsoft.com/en-us/library/gg406140.aspx" rel="nofollow">Microsoft PRISM's</a> <code>DataTemplateSelector</code></p> <p>There are a number of ways to hook up the <code>ChangeTabIndexCommand</code>. My preference is to use some kind of <a href="http://rachel53461.wordpress.com/2011/06/05/communication-between-viewmodels-with-mvvm/" rel="nofollow">Messaging System</a>, however you could also hook up the event in the Constructor of the MainViewModel.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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