【问题标题】:WPF Tab MarginsWPF 标签页边距
【发布时间】:2011-03-23 04:22:52
【问题描述】:

我有一个 WPF TabControl,带有一些 TabItems。如果有意义的话,我想要 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”之类的边距,我会在选项卡的左侧获得所需的效果,但这似乎是一个 hack,并且赢了不适用于右侧。

我在 VS 2010 中使用 WPF 4.0。

干杯!

【问题讨论】:

    标签: wpf wpf-controls wpftoolkit


    【解决方案1】:

    尝试使用这种风格。

       <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的controltemplate里面的tabpanel留边距

    查看链接了解更多

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

    【讨论】:

    • 谢谢。这似乎做到了。魔法似乎就在那个 TabPanel 中。我还不明白,但我相信这就是我想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多