xaml
<controls:TabControl x:Name="tabControlRoom" Grid.Row="1" Grid.Column="1" d:LayoutOverrides="Width, Height" ItemsSource="{Binding}" >
<controls:TabControl.ItemTemplate>
<DataTemplate>
<controls:TabItem Header="{Binding name}">
<StackPanel Margin="10" Orientation="Horizontal">
</StackPanel>
</controls:TabItem>
</DataTemplate>
</controls:TabControl.ItemTemplate>
</controls:TabControl>
and code
m_roomContext.Load(m_roomContext.GetRoomQuery());
tabControlRoom.DataContext = m_roomContext.Rooms;
when I open this page, then there is all the elements, but a second later I see only a white screen
error:
load operation failed for query 'GetRoom'. Unable to cast object of type 'Web.Room' to type 'System.Windows.Controls.TabItem'/'
Create converter
Create ControlTemplate:
And binding convert, controltemplate
taken from the blog binding-tabcontrol
When binding the TabControl there are two things you need to accomplish, one is the header content for the TabItem the other is the content for the selected TabItem, which is generally another user control.
The way have I've solved this in the past is to bind ItemsSource of the TabControl to a collection of view models, and to provide two data templates, one to supply the header content for the TabItem, an the other to supply the content for the selected TabItem, which maps to a view.