in my XAML code, I have a TabControl with multiple items. The problem I have is that I can not center the tabitems about the content area. The tabs are always starting on the left side, but I need them centered. This is my code:
在我的XAML代码中,我有一个包含多个项目的TabControl。我遇到的问题是我无法将关于内容区域的tabitems集中在一起。标签总是从左侧开始,但我需要它们居中。这是我的代码:
<TabControl>
<TabItem Header="Test 1" Style="{StaticResource LeftTab}" Height="40" />
<TabItem Header="Test 2" Style="{StaticResource MiddleTab}" />
<TabItem Header="Test 3" Style="{StaticResource MiddleTab}" />
<TabItem Header="Test 4" Style="{StaticResource RightTab}" />
</TabControl>
I do not know a property to center the items - any idea?
我不知道物品的中心 - 任何想法?
1 个解决方案
#1
41
Internally, the TabControl
uses a TabPanel
to layout the tabs. Using the default template, you just need to set the HorizontalAlignment
of the TabPanel
through a style:
在内部,TabControl使用TabPanel来布局选项卡。使用默认模板,您只需要通过样式设置TabPanel的HorizontalAlignment:
<TabControl>
<TabControl.Resources>
<Style TargetType="{x:Type TabPanel}">
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</TabControl.Resources>
<TabItem Header="Test 1" />
<TabItem Header="Test 2" />
<TabItem Header="Test 3" />
<TabItem Header="Test 4" />
</TabControl>
#1
41
Internally, the TabControl
uses a TabPanel
to layout the tabs. Using the default template, you just need to set the HorizontalAlignment
of the TabPanel
through a style:
在内部,TabControl使用TabPanel来布局选项卡。使用默认模板,您只需要通过样式设置TabPanel的HorizontalAlignment:
<TabControl>
<TabControl.Resources>
<Style TargetType="{x:Type TabPanel}">
<Setter Property="HorizontalAlignment" Value="Center" />
</Style>
</TabControl.Resources>
<TabItem Header="Test 1" />
<TabItem Header="Test 2" />
<TabItem Header="Test 3" />
<TabItem Header="Test 4" />
</TabControl>