How to style a WPF TabControl

A very good example of how to style a WPF TabControl.

From Brandon Cannaday at Switch on the code.

I use this Style to surround each TabItem Content with a ScrollViewer:


        <Style TargetType="{x:Type TabControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TabPanel Grid.Row="0" IsItemsHost="True" />
                            <ScrollViewer Grid.Row="1"
                                VerticalScrollBarVisibility="Auto"
                                Margin="5,5,5,5"
                                Background="White">
                                <ContentPresenter ContentSource="SelectedContent" />
                            </ScrollViewer>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Leave a Reply