Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF TabControl and DataTemplates
    text
    copied!<p>I've got a set of ViewModels that I'm binding to the ItemsSource property of a TabControl. Let's call those ViewModels AViewModel, BViewModel, and CViewModel. Each one of those needs to have a different ItemTemplate (for the header; because they each need to show a different icon) and a different ContentTemplate (because they have very different interaction models).</p> <p>What I'd like is something like this:</p> <p>Defined in Resource.xaml files somewhere:</p> <pre><code>&lt;DataTemplate x:Key="ItemTemplate" DataType="{x:Type AViewModel}"&gt; ... &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="ItemTemplate" DataType="{x:Type BViewModel}"&gt; ... &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="ItemTemplate" DataType="{x:Type CViewModel}"&gt; ... &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="ContentTemplate" DataType="{x:Type AViewModel}"&gt; ... &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="ContentTemplate" DataType="{x:Type BViewModel}"&gt; ... &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="ContentTemplate" DataType="{x:Type CViewModel}"&gt; ... &lt;/DataTemplate&gt; </code></pre> <p>Defined separately:</p> <pre><code>&lt;TabControl ItemTemplate="[ Some way to select "ItemTemplate" based on the type ]" ContentTemplate="[ Some way to select "ContentTemplate" based on the type ]"/&gt; </code></pre> <p>Now, I know that realistically, each time I define a DataTemplate with the same key the system is just going to complain. But, is there something I can do that's similar to this that will let me put a DataTemplate into a TabControl based on a name and a DataType?</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