views:

19

answers:

1

Upper part of TabControl consists of TabItem controls. Is there a way to reuse remaining space there to put some WPF content?

I think I could use a "fake" TabItem with different styling and put my stuff in TabItem.Header but I was hoping there's a better way.

Solution

Based on the answer below, I got the desired behavior by wrapping TabPanel in the template below within e.g. StackPanel and adding my additional content after it.

<StackPanel Orientation="Horizontal">
   <TabPanel 
    Grid.Row="0"
    Panel.ZIndex="1" 
    Margin="0,0,4,-1" 
    IsItemsHost="True"
    Background="Transparent" />
    <TextBlock>Foo</TextBlock>
</StackPanel>
A: 

You can use a template and make it do whatever you want, that is the power of WPF. Here is a nice article on customizing the TabControl and the TabItem controls.

< EDIT Adding code for TabControl template from Switch On The Code article>

<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="0,0,4,-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>

all you have to do is add your content to the Template, the part that holds the tab items is the <TabControl>

Muad'Dib
That doesn't answer my question. I've seen many articles describing how to modify the look of TabItem (including the one you linked to).What I'm asking, however, is how to use the space *after* TabItem(s).
Krzysztof Kowalczyk
ahh, but it DOES answer your question. Look about 1/2 way down where he redefines the control template for the tab control. All you have to do is modify the template for the tab control, placing whatever you want in that area after the <TabPanel>
Muad'Dib
Thanks, that explanation was helpful. I got what I wanted by wrapping TabPanel within e.g. StackPanel.
Krzysztof Kowalczyk