Mic*_* T. 8 wpf wpftoolkit wpf-controls
我有一个WPF TabControl,有一些TabItems.我想要TabItems组左侧和右侧的边距,如果这是有道理的.
我将在下面绘制一些ASCII艺术来说明问题.我想在第一个标签的左边有一个固定的边距,但我还想在标签三的右边有一个固定的边距.
|--------------------------------------------------|
| |-----||-----||-----| |
| <-Margin-> | 1 || 2 || 3 | <-Margin-> |
|------------| ||-----||-----|-----------------|
| |
| How do I get margin or padding on both |
| sides of my tabs? |
| |
| |
|--------------------------------------------------|
Run Code Online (Sandbox Code Playgroud)
选项卡的数量是不受限制的,因此它们会在添加更多内容时堆叠.它需要正确地工作.
另外,请注意,我不想让整个标签控件变小.只是tabitem标签或标题或它们是什么.
我发现如果我将标签设置为具有"60,0,-60,0"之类的边距,我会在标签的左侧获得所需的效果,但这看起来像是黑客,并且不起作用对于右手边.
我在VS 2010中使用WPF 4.0.
干杯!
尝试使用此样式。
<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>
Run Code Online (Sandbox Code Playgroud)
编辑
您可以将边距直接提供给tabcontrol的controltemplate内的tabpanel
检查链接了解更多
http://www.switchonthecode.com/tutorials/the-wpf-tab-control-inside-and-out