WPF TabControl and DataTemplates
datatemplate, tabcontrol, wpf
Solution
One way would be to use `DataTemplateSelector`s and have each one resolve the resource from a separate `ResourceDictionary`.
Problem
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). What I'd like is something like this: Defined in Resource.xaml files somewhere: ``` <DataTemplate x:Key="ItemTemplate" DataType="{x:Type AViewModel}"> ... </DataTemplate> <DataTemplate x:Key="ItemTemplate" DataType="{x:Type BViewModel}"> ... </DataTemplate> <DataTemplate x:Key="ItemTemplate" DataType="{x:Type CViewModel}"> ... </DataTemplate> <DataTemplate x:Key="ContentTemplate" DataType="{x:Type AViewModel}"> ... </DataTemplate> <DataTemplate x:Key="ContentTemplate" DataType="{x:Type BViewModel}"> ... </DataTemplate> <DataTemplate x:Key="ContentTemplate" DataType="{x:Type CViewModel}"> ... </DataTemplate> ``` Defined separately: ``` <TabControl ItemTemplate="[ Some way to select "ItemTemplate" based on the type ]" ContentTemplate="[ Some way to select "ContentTemplate" based on the type ]"/> ``` 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?