Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Add an <code>ICommand</code> to your <code>MainViewModel</code> for adding a new item to your <code>ObservableCollection</code>, and use a <code>RelativeSource</code> binding to find the command from within the <code>TabItem</code></p> <p>So your MainViewModel would have</p> <pre class="lang-cs prettyprint-override"><code>ObservableCollection&lt;IViewModel&gt; TabItems IViewModel SelectedTabItem ICommand AddTabCommand </code></pre> <p>where <code>AddTabCommand</code> basically does </p> <pre class="lang-cs prettyprint-override"><code>void AddTab(IViewModel newItem) { TabItems.Add(newItem); SelectedTabItem = newItem; } </code></pre> <p>and your UI would look something along the lines of this</p> <pre><code>&lt;DataTemplate DataType="{x:Type local:SelectReportViewModel}"&gt; &lt;Grid&gt; ... &lt;!-- Use the CommandParameter property to pass specified ReportItemViewModel to open --&gt; &lt;Button Command="{Binding DataContext.AddTabCommand, RelativeSource={RelativeSource AncestorType={x:Type TabControl}}}" /&gt; ... &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;TabControl ItemsSource="{Binding TabItems}" /&gt; </code></pre> <p>Another alternative is to use some kind of event system, such as MVVM Light's <code>Messenger</code> or Microsoft Prism's <code>EventAggregator</code>, to broadcast/subscribe to events. </p> <p>Your <code>MainViewModel</code> would subscribe to <code>AddTabEvents</code>, while your <code>SelectReportViewModel</code> would broadcast those events anytime a new tab should be added. I have a brief summary on my blog article about <a href="http://rachel53461.wordpress.com/2011/06/05/communication-between-viewmodels-with-mvvm/" rel="nofollow">communication between ViewModels</a> if you're interested.</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.
    3. 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