WPF 制表符边距

发布于 2024-10-25 18:05:16 字数 944 浏览 2 评论 0原文

我有一个 WPF TabControl,带有一些 TabItem。我希望 TabItems 组的左侧和右侧有边距,如果这有意义的话。

我将在下面画一些 ASCII 艺术来说明这一点。我想要在选项卡一的左侧有固定的边距,但我也想要在选项卡三的右侧有固定的边距。

|--------------------------------------------------|
|            |-----||-----||-----|                 |
| <-Margin-> |  1  ||  2  ||  3  | <-Margin->      |
|------------|     ||-----||-----|-----------------|
|                                                  |
|  How do I get margin or padding on both          |
|    sides of my tabs?                             |
|                                                  |
|                                                  |
|--------------------------------------------------|

选项卡的数量是无限的,因此随着添加更多选项卡,它们将堆叠起来。为此,它需要正确工作。

另外,请注意,我不想使整个选项卡控件变小。只是 tabitem 选项卡或标题或其他任何内容。

我发现如果我将选项卡设置为具有类似于“60,0,-60,0”的边距,我会在选项卡左侧获得所需的效果,但这似乎是一种黑客行为,并且不起作用对于右侧。

我在 VS 2010 中使用 WPF 4.0。

干杯!

I have a WPF TabControl, with some TabItems. I want margins on the left and right of the TabItems group, if that makes sense.

I'm going to draw some ASCII art below to make the point. I want a fixed margin to the left of tab one, but I also want a fixed margin to the right of tab three.

|--------------------------------------------------|
|            |-----||-----||-----|                 |
| <-Margin-> |  1  ||  2  ||  3  | <-Margin->      |
|------------|     ||-----||-----|-----------------|
|                                                  |
|  How do I get margin or padding on both          |
|    sides of my tabs?                             |
|                                                  |
|                                                  |
|--------------------------------------------------|

The number of tabs is unlimited, so they will stack as more are added. It needs to work correctly for that.

Also, note, that I don't want to make the whole tab control smaller. Just the tabitem tabs or headers or whatever they are.

I found that if I set the tabs to have a margin of something like "60,0,-60,0", I get the desired effect to the left of the tabs, but that seems like a hack, and won't work for the right hand side.

I am using WPF 4.0 in VS 2010.

Cheers!

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

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

发布评论

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

评论(1

以往的大感动 2024-11-01 18:05:16

尝试使用这种风格。

   <Style  TargetType="{x:Type TabControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TabPanel
             Grid.Row="0"
             Panel.ZIndex="1"
             Margin="60,0,60,-1"
             IsItemsHost="True"
             Background="Transparent" />
                            <Border
             Grid.Row="1"
             BorderBrush="Black"
             BorderThickness="1"
             CornerRadius="0, 12, 12, 12" >
                                <Border.Background>
                                    <LinearGradientBrush>
                                        <GradientStop Color="LightBlue" Offset="0" />
                                        <GradientStop Color="White" Offset="1" />
                                    </LinearGradientBrush>
                                </Border.Background>
                                <ContentPresenter ContentSource="SelectedContent" />
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

编辑

您可以直接将边距赋予 tabcontrol 的控件模板内的 tabpanel

检查链接了解更多

http://www.switchonthecode.com/tutorials/the-wpf-tab-control-inside-and-out

Try using this style.

   <Style  TargetType="{x:Type TabControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TabPanel
             Grid.Row="0"
             Panel.ZIndex="1"
             Margin="60,0,60,-1"
             IsItemsHost="True"
             Background="Transparent" />
                            <Border
             Grid.Row="1"
             BorderBrush="Black"
             BorderThickness="1"
             CornerRadius="0, 12, 12, 12" >
                                <Border.Background>
                                    <LinearGradientBrush>
                                        <GradientStop Color="LightBlue" Offset="0" />
                                        <GradientStop Color="White" Offset="1" />
                                    </LinearGradientBrush>
                                </Border.Background>
                                <ContentPresenter ContentSource="SelectedContent" />
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

EDIT

You can give the margin directly to the tabpanel inside the controltemplate of tabcontrol

Check the link for more

http://www.switchonthecode.com/tutorials/the-wpf-tab-control-inside-and-out

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