TabControl填充不适用于经典主题

时间:2022-11-25 14:13:45

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

有谁知道TabControl的padding属性为什么不用经典主题渲染但适用于luna主题?

TabControl填充不适用于经典主题

TabControl填充不适用于经典主题

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

XAML非常基础。我已经制作了左侧填充50,因此截屏中的问题很明显。

<!-- 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?

有什么关于我缺少的经典主题,例如所有填充都被忽略了?

1 个解决方案

#1


4  

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.

使用ShowMeTheTemplate或Microsoft Expression Blend工具之一,您可以检查Microsoft默认为不同主题实现的控件模板。

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

对于Windows Classic,TabControl的控件模板如下所示:

<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:

对于Luna来说,它是这样的:

<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.

在Luna中,TabControl的填充绑定到ContentPresenter的边缘;在Windows Classic中,边距设置为2。

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

就个人而言,我认为,这是一个错误。您可能想在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>

#1


4  

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.

使用ShowMeTheTemplate或Microsoft Expression Blend工具之一,您可以检查Microsoft默认为不同主题实现的控件模板。

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

对于Windows Classic,TabControl的控件模板如下所示:

<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:

对于Luna来说,它是这样的:

<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.

在Luna中,TabControl的填充绑定到ContentPresenter的边缘;在Windows Classic中,边距设置为2。

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

就个人而言,我认为,这是一个错误。您可能想在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>