wpf 在 TabControl 中调整 TabItem 标题大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31770632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resize TabItem header size inside TabControl
提问by berry wer
I am using MahAppsTabControland i have several TabItems:
我正在使用MahAppsTabControl,我有几个TabItems:
<TabControl Name="tabControl" FontSize="12">
<TabItem Header="Statistics" />
</TabControl>
I try to change the fontsize of the TabControland TabItemsin order to resize my headers but it seems that this not changing anything.
我试图改变font的大小TabControl,并TabItems以调整我的头,但似乎这不是什么变化。
回答by punker76
You should use the attached property HeaderFontSizeto set the header font size of the tav items.
您应该使用附加属性HeaderFontSize来设置 tav 项目的标题字体大小。
<TabControl Name="tabControl">
<TabItem Header="Statistics" Controls:ControlsHelper.HeaderFontSize="12" />
</TabControl>
or
或者
<TabControl Name="tabControl">
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="12" />
</Style>
</TabControl.Resources>
<TabItem Header="Statistics" />
</TabControl>
Hope that helps.
希望有帮助。
回答by Praveen M B
Put the below code in Window.Resources
将以下代码放在 Window.Resources 中
<Window
......
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
......
>
<Window.Resources>
<Style x:Key="MenuLevel2" BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type TabItem}">
<Setter Property="mah:ControlsHelper.HeaderFontSize" Value="15"></Setter>
</Style>
<Window.Resources>
In the TabItem section add the style details.
在 TabItem 部分添加样式详细信息。
<TabItem Header="Dimension Alias" Style="{DynamicResource MenuLevel2}">
This worked for me.
这对我有用。
回答by Andrej Kmetík
In 2.* versions of MahApps.Metro it changes to:
在 2.* 版本的 MahApps.Metro 中,它更改为:
<TabControl Name="tabControl">
<TabItem Header="Statistics" Controls:HeaderedControlHelper.HeaderFontSize="12" />
</TabControl>
or
或者
<TabControl Name="tabControl">
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="Controls:HeaderedControlHelper.HeaderFontSize" Value="12" />
</Style>
</TabControl.Resources>
<TabItem Header="Statistics" />
</TabControl>
Source: https://github.com/MahApps/MahApps.Metro/issues/3711
来源:https: //github.com/MahApps/MahApps.Metro/issues/3711
Documentation is not available at the time of writing.
在撰写本文时,文档不可用。
回答by Marco Concas
In my case this has solved my problem:
就我而言,这解决了我的问题:
<TabControl>
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="12" />
</Style>
</TabControl.Resources>
</TabControl>
回答by Hadiro Tafoua
since tabItems is a list of item having some common bindings modifying one of Tabitem header height will automatically do for the others
因为 tabItems 是具有一些常见绑定的项目列表,修改 Tabitem 标题高度之一将自动为其他人做
<TabControl>
<TabItem >
<TabItem.Header>
<Label Height="30" Content="Main" FontSize="16" >
</Label>
</TabItem.Header>
</TabItem>
<TabItem Header="Second header" >
<TabItem Header="Third header" >
</TabControl>

