.net - TabControl 填充不适用于经典主题

标签 .net wpf xaml themes padding

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

Classic

Luna

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>

我是否缺少有关经典主题的内容,例如所有填充都被忽略了吗?

最佳答案

使用其中一种工具 ShowMeTheTemplateMicrosoft Expression Blend ,您可以查看 Microsoft 针对不同主题默认实现的控件模板。

对于 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>

对于 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>

在Luna中,TabControl的Padding绑定(bind)到ContentPresenter的边距;在 Windows Classic 中,边距设置为 2。

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

作为解决方法,您可以定义自己的内容模板:

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

关于.net - TabControl 填充不适用于经典主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9745086/

相关文章:

c# - WPF 绑定(bind)设计时 "Property Expected"错误

.net - Microsoft.Azure.Management.DataLake.Store 与 Microsoft.Azure.DataLake.Store

c# - 如何检查我的 .NET 程序集的新鲜度?

.net - Windows XP 和 7 之间发生了什么变化导致我的 Mono C# 应用程序崩溃?

c# - 如何检测控件上的完整鼠标单击(向下和向上)?

c# - 从 WPF 应用程序中的代码访问 UserControl

c# - WPF 中的 Windows 图标属性,需要标记扩展吗?

c# - 如何将参数传递给 C# 中的公共(public)类?

c# - 摇动动画(3d版)

c# - MVVM wpf在 View 模型之间传递参数