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 开发者_JAVA百科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!
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
精彩评论