Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I doubt that this is what you really want to do, if you have different ViewModels you can still bind your control to a collection of those ViewModels and template them as necessary.</p> <p>You just need to create different DataTemplates at different level, here is an example (which directly uses models but that should not matter right now):</p> <pre><code>&lt;TabControl&gt; &lt;TabControl.ItemsSource&gt; &lt;!-- This is just sample data, normally you would bind this to an ObservableCollection&lt;ViewModelBase&gt; or something similar --&gt; &lt;x:Array Type="{x:Type sys:Object}"&gt; &lt;local:Employee Name="John" Occupation="Programmer"/&gt; &lt;local:Employee Name="Steve" Occupation="Coffee Getter"/&gt; &lt;local:Machine Manufacturer="iCorp" Model="iMachine"/&gt; &lt;local:Machine Manufacturer="iCorp" Model="iMachine G2"/&gt; &lt;local:Employee Name="Marc" Occupation="GUI Designer"/&gt; &lt;/x:Array&gt; &lt;/TabControl.ItemsSource&gt; &lt;TabControl.Resources&gt; &lt;!-- These datatemplates define the tab-header appearance, by placing them in the TabControl.Resources and setting the DataType they get applied automatically, just make one light-weight template for each ViewModel --&gt; &lt;DataTemplate DataType="{x:Type local:Employee}"&gt; &lt;TextBlock&gt; &lt;Run Text="{Binding Name}"/&gt; &lt;Run Text="("/&gt; &lt;Run Text="{Binding Occupation}"/&gt; &lt;Run Text=")"/&gt; &lt;/TextBlock&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type local:Machine}"&gt; &lt;TextBlock&gt; &lt;Run Text="{Binding Manufacturer}"/&gt; &lt;Run Text=" - "/&gt; &lt;Run Text="{Binding Model}"/&gt; &lt;/TextBlock&gt; &lt;/DataTemplate&gt; &lt;ContentControl x:Key="MainContent" Content="{Binding}"&gt; &lt;ContentControl.Resources&gt; &lt;!-- This represents the content of the TabItems, you probably do not need to create DataTemplates but since you could use a View of the ViewModels instead --&gt; &lt;DataTemplate DataType="{x:Type local:Employee}"&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding Name}"/&gt; &lt;TextBlock Text="{Binding Occupation}"/&gt; &lt;TextBlock Text="{Binding Id}"/&gt; &lt;TextBlock Text="{Binding IsActive}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;DataTemplate DataType="{x:Type local:Machine}"&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding Manufacturer}"/&gt; &lt;TextBlock Text="{Binding Model}"/&gt; &lt;TextBlock Text="{Binding VintageYear}"/&gt; &lt;TextBlock Text="{Binding Price}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ContentControl.Resources&gt; &lt;/ContentControl&gt; &lt;/TabControl.Resources&gt; &lt;TabControl.ContentTemplate&gt; &lt;!-- Setting the content to the resource --&gt; &lt;DataTemplate&gt; &lt;Border&gt; &lt;StaticResource ResourceKey="MainContent"/&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/TabControl.ContentTemplate&gt; &lt;/TabControl&gt; </code></pre> <p>I might try to get the specifics for MVVM implemented but this hopefully already gives an idea of how it can be approached.</p> <p>You might want to set up a template selector (<code>TabControl.ContentTemplateSelector</code>) to get the right views for your ViewModels.</p>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    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