I want a TabControl where each tab item represents a (Employee)ViewModel; the header should be the DisplayName property of that view model, and the content should be a user control (EmployeeDetailsView) that has a data context of the view model.
So pidgeon xaml (is there such a thing??):
<TabControl x:Name="Items">
<TabItem Header="DisplayName" Content=local:EmployeeDetailsView />
<TabControl>
What should my real XAML look like?
Cheers,
Berryl
EDIT for Vortex
<TabControl x:Name="Items" >
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding DisplayName}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl>
<local:EmployeeDetailView/>
</ContentControl>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
Best Answer
In WPF it is quite simple. But in silverlight I used custom TabControl.
Silverlight
You can find source and example here (MyTabControl.cs), where I've answered a similar question.
And now your code must be something like:
In code-behind or somewhere:
WPF
WPF has built-in support of DataTemplates in the TabControl, so I have to do a few minor changes in XAML: