TabControl的填充不与经典主题工作不与、经典、主题、工作

2023-09-05 01:03:13 作者:我心太脏你别触碰

有谁知道为什么的TabControl的填充属性不会呈现经典的主题,但工程月神主题?

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

该XAML是非常基本的。因此,这个问题是显而易见的截图我所做的左填充50。

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?

推荐答案

的工具使用一个 ShowMeTheTemplate 或微软前pression混合,你可以检查,微软已经在默认情况下为不同的主题实现的控制模板。

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.

有关Windows经典的的TabControl的控件模板看起来是这样的:

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>

在月神,在的TabControl的填充势必会的内容presenter保证金;在Windows经典,边距设置为2。

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

我个人认为,这是一个错误。您可能要创建 http://connect.microsoft.com/ 的bug报告。

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>