WPF 选项卡控制标题之间的间距

发布于 2024-08-06 18:46:02 字数 114 浏览 7 评论 0原文

WPF Tabcontrol 的默认行为是将选项卡标题彼此相邻放置,之间没有任何空白。如果我想指定标题之间的间隙怎么办?我必须为此定义一个控制模板吗?我对粮食计划署比较陌生,非常感谢任何帮助。

谢谢

The default behavior of the WPF Tabcontrol is to place the Tab Headers adjacent to each other, without any empty space in between. What if I wanted to specify a gap between the headers? Do I have to define a control template for this? I'm relatively new to WFP and any help is appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤芳又自赏 2024-08-13 18:46:02

我相信您需要为 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 -> 引用它选项卡项。

I believe you will need to define a custom control template for the TabItem, maybe even one for the TabControl. Here is an example of a TabItem that uses a spacer for some separation.

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

Hopefully that is a nudge in the right direction; you will still need to add that as a style resource and reference it from your TabControl -> TabItem.

情痴 2024-08-13 18:46:02

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

It is easy to add space by doing it in the designer. Select the Tab you want to move, by starting with the rightmost tab. Then hold ctrl and use the right arrow key to move the tab to the right. Do the same with the rest of the tabs. Then you can manually adjust the margin in the xaml code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文