#911 – Use ItemTemplate to Control Content on Tabs
September 20, 2013 2 Comments
You can use the ItemContainerStyle of a TabControl to dictate the content that appears on the tabs, creating a style that sets each TabItem’s HeaderTemplate.
As a slightly more straightforward way to do the same thing, you can just set the TabControl’s ItemTemplate property to a DataTemplate that defines the content for each tab.
<TabControl Margin="5" ItemsSource="{Binding RomanDudes}"> <!-- Change ItemTemplate to control content on tabs --> <TabControl.ItemTemplate> <DataTemplate> <StackPanel> <Image Source="{Binding Image}" Height="50"/> <TextBlock Text="{Binding Name}" HorizontalAlignment="Center"/> </StackPanel> </DataTemplate> </TabControl.ItemTemplate> <!-- Change ContentTemplate to control main content --> <TabControl.ContentTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="10"> <Image Source="{Binding Image}" Height="80"/> <StackPanel Margin="10"> <TextBlock Text="{Binding Name}"/> <TextBlock Text="{Binding ReignStart}"/> <TextBlock Text="{Binding ReignEnd}"/> <TextBlock Text="{Binding KnownFor}"/> </StackPanel> </StackPanel> </DataTemplate> </TabControl.ContentTemplate> </TabControl>
Pingback: Dew Drop – September 20, 2013 (#1,628) | Morning Dew
Pingback: #908 – Binding a TabControl to a List of Objects, part II | 2,000 Things You Should Know About WPF