I would like to use a TabControl as the main navigation in the application I am working on. So I would like to make the font in the headers of the TabItems bigger and also give it another background-color. However, I do not want this to be inherited. For example, if I use this code:
<TabControl FontSize="18pt">
  <TabItem Header="Tab 1">
    <Button>Button 1</Button>
  </TabItem>
</TabControl>
The font in the button is also 18pt big. I know that this is normal dependency property behaviour because the property is inherited, but that's not what I want in this case. I would like to change the TabItems without changing anything in the children. Isn't that possible? Because re-setting all children to default values is a PITA.
Thanks for your time.
Define the Header as an explicit control (TextBlock or Label for instance), on which you apply a style :
<TabControl FontSize="18pt">
  <TabItem>
    <TabItem.Header>
        <TextBlock Style="{StaticResource tabHeaderStyle}">Tab 1</TextBlock>
    </TabItem.Header>
    <Button>Button 1</Button>
  </TabItem>
</TabControl>
                        You have to rethink this a bit. You can't just say "Don't inherit," because the control has to inherit its property values from somewhere.
This works:
  <TabControl x:Name="Test" FontSize="36">
    <TabControl.Resources>
      <Style TargetType="Button">
        <Setter Property="FontSize" Value="{Binding ElementName=Test, Path=FontSize}"/>
      </Style>        
    </TabControl.Resources>
    <TabItem Header="Test" FontSize="24">
      <Button>Another test</Button>
    </TabItem>
  </TabControl>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With