简体   繁体   English

如何在 TabControl 中设置 header 的高度?

[英]How to set the height of the header in a TabControl?

How can I set the height of the header in a TabControl (marked in red in the attached picture)?如何在TabControl中设置 header 的高度(在附图中标记为红色)? I figured out how to control the height of the single tabs (marked in blue) but could not find a way to change the height of the complete header line.我想出了如何控制单个选项卡(标记为蓝色)的高度,但找不到更改完整 header 行的高度的方法。

标签控件的标题,整个标题行的高度用红色箭头表示,标签标题的高度用蓝色箭头表示。

In order to change the tab header dimensions or margin, you have to edit the control template of the TabControl .为了更改选项卡 header 尺寸或边距,您必须编辑TabControl的控件模板。 Extract the default style and its control template using Visual Studio or Blend and adapt the section for TabPanel , which hosts the tab headers.使用 Visual Studio 或 Blend提取默认样式及其控件模板,并为承载选项卡标题的TabPanel调整该部分。

<TabPanel x:Name="headerPanel" Background="Transparent" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/>

Update for your comment: When you decrease the height of the TabPanel , the text in the tab header might appear to be cut-off, although there is space left.更新您的评论:当您降低TabPanel的高度时,选项卡 header 中的文本可能会被截断,尽管还有空间。 This is caused by the default Padding of the item container.这是由项目容器的默认Padding引起的。 You can remove it using a style.您可以使用样式将其删除。

<TabControl.ItemContainerStyle>
   <Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
      <Setter Property="Padding" Value="0"/>
   </Style>
</TabControl.ItemContainerStyle>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM