【问题标题】:How to set the hight of TabControl Header in WPF?如何在 WPF 中设置 TabControl Header 的高度?
【发布时间】:2019-06-14 07:51:48
【问题描述】:

我在 App.xaml 中设置了样式

<Style TargetType="TextBlock">
        <Setter Property="Margin" Value="3"/>
</Style>

我意识到这也增加了我的 TabControl 中的标题,这不是我的意图。

我试图在 TabControl Header 中恢复高度但没有成功。 (并且对 TabItem 也进行了同样的尝试)

        <TabControl.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="Margin" Value="0"/>
            </Style>    
        </TabControl.Resources>

更新 1:一个建议是在 TabControl 中为 TextBlocks 定义一个空样式。它没有帮助。

    <Style TargetType="TabControl">
        <Style.Resources>
            <Style TargetType="TextBlock" />
        </Style.Resources>
    </Style>

【问题讨论】:

标签: c# wpf


【解决方案1】:

试试这样的 FontSize:

   <TabControl.Style>
   <Style TargetType="{x:Type TabControl}">
   <Setter Property="FontSize" Value="27"/>
   </Style>
   </TabControl.Style>

【讨论】:

    【解决方案2】:

    通过增加边距 (Margin="15,20") top(example : 20) 可以增加标签控件菜单标题的高度,

    <TabControl.Resources>
                        <Style TargetType="TabItem">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="TabItem">
                                        <Grid Name="Panel">
                                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="15,20" />
                                        </Grid>
                                   </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>                      
     </TabControl.Resources>
    

    【讨论】:

      【解决方案3】:

      谢谢@mm8。我从 App.xaml 中删除了样式并将其放入 Window.Resources。现在 TabControl 标头不受影响。

      【讨论】:

        猜你喜欢
        • 2010-11-07
        • 2016-11-01
        • 2016-09-14
        • 2014-06-12
        • 2011-12-08
        • 2021-01-20
        • 1970-01-01
        • 1970-01-01
        • 2012-07-11
        相关资源
        最近更新 更多