【问题标题】:WPF tab control spacing between headersWPF选项卡控制标题之间的间距
【发布时间】:2010-12-02 10:39:59
【问题描述】:

WPF 选项卡控件的默认行为是将选项卡标题彼此相邻放置,中间没有任何空格。如果我想指定标题之间的间隙怎么办?我必须为此定义一个控制模板吗?我对 WFP 比较陌生,如果有任何帮助,我将不胜感激。

谢谢

【问题讨论】:

    标签: wpf header tabcontrol spacing gaps-in-visuals


    【解决方案1】:

    我相信您需要为 TabItem 定义一个自定义控件模板,甚至可能为 TabControl 定义一个。下面是一个 TabItem 示例,它使用间隔符进行一些分隔。

    <Style
        x:Key="SpacedTab"
        TargetType="{x:Type TabItem}">
        <Setter
            Property="Template">
            <Setter.Value>
                <ControlTemplate
                    TargetType="{x:Type TabItem}">
                    <Border
                        x:Name="Spacer"
                        Width="Auto"
                        Height="Auto"
                        Padding="0 0 5 0"
                        Margin="0 0 0 0"
                        BorderBrush="Transparent"
                        BorderThickness="0">
                        <Border
                            x:Name="Border"
                            MinWidth="150"
                            Width="Auto"
                            Height="30"
                            Background="Gray"
                            BorderBrush="DarkGray"
                            BorderThickness="0,0,0,0"
                            CornerRadius="6,6,0,0"
                            Cursor="Hand"
                            VerticalAlignment="Bottom">
                            <ContentPresenter
                                x:Name="ContentSite"
                                TextElement.FontSize="10pt"
                                TextElement.FontFamily="Arial"
                                TextElement.Foreground="Black"
                                VerticalAlignment="Center"
                                HorizontalAlignment="Center"
                                ContentSource="Header"
                                Margin="8,3,8,3"
                                Width="Auto"
                                Height="Auto" />
                        </Border>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    希望这是朝着正确方向的推动;您仍然需要将其添加为样式资源并从您的 TabControl -> TabItem 引用它。

    【讨论】:

    • 好的,我试试看。谢谢
    【解决方案2】:

    在设计器中添加空间很容易。从最右边的选项卡开始,选择要移动的选项卡。然后按住 ctrl 并使用右箭头键将选项卡向右移动。对其余选项卡执行相同操作。然后可以在xaml代码中手动调整margin。

    【讨论】:

    • 不需要设计师。代码中的累积边距也有效,因此 [tab] 空间 [tab] [tab] 空间 [tab] 的第一个选项卡的左右边距为 0,然后为后两个选项卡的 x 和最后一个选项卡的 2x,其中 x 是宽度“空间”
    猜你喜欢
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2015-06-16
    • 2014-05-09
    • 2021-05-08
    相关资源
    最近更新 更多