WPF:在 TabControl 中居中 TabItems [英] WPF: Center TabItems in a TabControl

查看:58
本文介绍了WPF:在 TabControl 中居中 TabItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 XAML 代码中,我有一个包含多个项目的 TabControl.我的问题是我无法将关于内容区域的 tabitems 居中.标签总是从左侧开始,但我需要它们居中.这是我的代码:

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:

<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?

推荐答案

在内部,TabControl 使用 TabPanel 来布局选项卡.使用默认模板,只需通过样式设置TabPanelHorizo​​ntalAlignment即可:

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

这篇关于WPF:在 TabControl 中居中 TabItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆