Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabControl padding doesn't work with classic theme

Does anyone know why the padding property of TabControl doesn't render with classic theme but works for luna theme?

Classic

Luna

The XAML is very basic. I've made the left padding 50 so that the problem is obvious in the screenshots.

<!-- Tab control styling -->
        <Style TargetType="{x:Type TabControl}">
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="1,1,1,1" />
            <Setter Property="Padding" Value="50,5,10,5" />
            <Setter Property="Margin" Value="3.5" />
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" />
        </Style>

Is there something about classic theme that I'm missing e.g. all padding is ignored?

like image 442
dior001 Avatar asked Jul 16 '26 20:07

dior001


1 Answers

Using one of the tools ShowMeTheTemplate or Microsoft Expression Blend, you can inspect the control templates that Microsoft has implemented by default for the different themes.

For Windows Classic, the TabControl's control template looks like this:

<ControlTemplate TargetType="{x:Type TabControl}">
    <Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
        ...
        <TabPanel .../>
        <Grid ...>
            <Microsoft_Windows_Themes:ClassicBorderDecorator ...>
                <ContentPresenter x:Name="PART_SelectedContentHost" Margin="2,2,2,2" .../>
            </Microsoft_Windows_Themes:ClassicBorderDecorator>
        </Grid>
    </Grid>
    <ControlTemplate.Triggers>
       ...
    </ControlTemplate.Triggers>
</ControlTemplate>

For Luna, it like this:

<ControlTemplate TargetType="{x:Type TabControl}">
    <Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
        ...
        <TabPanel .../>
        <Border ...>
            <ContentPresenter x:Name="PART_SelectedContentHost" Margin="{TemplateBinding Padding}" .../>
        </Border>
    </Grid>
    <ControlTemplate.Triggers>
       ...
    </ControlTemplate.Triggers>
</ControlTemplate>

In Luna, the Padding of the TabControl is bound to the margin of the ContentPresenter; in Windows Classic, the margin is set to 2.

Personally, I think, this is a bug. You might want to create a bug report on http://connect.microsoft.com/ .

As a workaround, you could define your own content template:

<TabControl>
    <TabControl.ContentTemplate>
        <DataTemplate>
            <ContentPresenter Content="{Binding}" Margin="50,5,10,5"/>
        </DataTemplate>
    </TabControl.ContentTemplate>
    ...
<TabControl>

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!