Thursday, March 11, 2010

How to set the TabItem Header in a Silverlight TabControl using Prism

In this piece of XAML it's assumed that the view being placed into the TabControl region has it's DataContext bound to a view model containing a HeaderInfo property.

For the complete example see ViewInjectionComposition quick start and have a look at the EmployeeDetailsView.

The trick to displaying the header is to override the HeaderTemplate property on the TabItem using a style.


<UserControl.Resources>
<Style TargetType="controls:TabItem" x:Key="TabItemStyle">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding HeaderInfo}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>

<Grid x:Name="LayoutRoot">
<controls:TabControl
Regions:RegionManager.RegionName="MainRegion"
Regions:TabControlRegionAdapter.ItemContainerStyle="{StaticResource TabItemStyle}"
>
</controls:TabControl>
</Grid>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.