WPF Tab Fields

I have a WPC TabControl with some TabItems. I want the fields to the left and right of the TabItems group, if that makes sense.

Below I will talk about ASCII art to understand the essence. I want the fixed margin to the left of the tab one, but I also want the fixed margin to the right of the 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 not limited, so they will add up as you add more. To do this, you need to work correctly.

Also, note that I do not want the entire tab control to be smaller. Only tabitem tabs or headers or whatever they are.

I found that if I set tabs with a margin of approximately “60.0, -60.0”, I get the desired effect to the left of the tabs, but it seems to be a hack and win work on the right side.

I am using WPF 4.0 in VS 2010.

Hooray!

+7
source share
1 answer

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 specify the margin directly on the tab inside the tabcontrol control panel

Check out the link for more

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

+4
source

All Articles