I am having a problem when attempting to host a UserControl as Tab Content within a Tab Item in a TabControl.
My code is structured as follows:
I have a view model which is supposed to be rendered into a View via a DataTemplate.
<DataTemplate x:Key="TabItemContentTemplate" DataType="{x:Type ViewModels:MyViewModel}">
<Views:MyView />
</DataTemplate>
I would like to present this view in
a TabControl (actually a
XamTabControl, but either way, the
issue remains.)
<UserControl>
<UserControl.Resources>
<DataTemplate x:Key="TabItemHeaderTemplate">
<StackPanel>
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=Description}"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="TabItemContentTemplate" DataType="{x:Type ViewModels:MyViewModel}">
<Views:MyView />
</DataTemplate>
<Style x:Key="TabItemContainerStyle" TargetType="Controls:TabItemEx">
<Setter Property="Header" Value="{Binding}"/>
<Setter Property="HeaderTemplate"
Value="{DynamicResource TabItemHeaderTemplate}"/>
<Setter Property="Content" Value="{Binding}"/>
<Setter Property="ContentTemplate"
Value="{DynamicResource TabItemContentTemplate}"/>
</Style>
</UserControl.Resources>
<Grid >
<Controls:XamTabControl
ItemsSource="{Binding Items}"
ItemContainerStyle="{DynamicResource TabItemContainerStyle}"
TabStripPlacement="Left"
TabLayoutStyle="SingleRowAutoSize"
AllowTabClosing="True"
Grid.Row="1"
TabItemCloseButtonVisibility="WhenSelectedOrHotTracked">
</Controls:XamTabControl>
</Grid>
</UserControl>
The issue is that the content does not render. The Tab header does render fine, however, there is no content in the tabs.
I am fairly certain the issue lies within the View/Viewmodel mapping as when I change the templates to the following, I do get content rendered:
<DataTemplate x:Key="TabItemHeaderTemplate">
<Grid>
<TextBlock Text="{Binding Header}"/>
<Ellipse Fill="Red" Width="40" Height="40" Margin="0,20,0,0"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TabItemContentTemplate">
<Ellipse Fill="Green"/>
</DataTemplate>
<Style x:Key="TabItemContainerStyle" TargetType="Controls:TabItemEx">
<Setter Property="Header" Value="{Binding}"/>
<Setter Property="HeaderTemplate"
Value="{StaticResource TabItemHeaderTemplate}"/>
<Setter Property="Content" Value="{Binding}"/>
<Setter Property="ContentTemplate"
Value="{StaticResource TabItemContentTemplate}"/>
</Style>
Does anyone have an idea what I am doing wrong here?
thanks in advance!
Solved this. the BAML was corrupted due to a re-name operation! 🙁