walkerstewart

walkerstewart


  • Name: [not set]
  • Favorite Languages: [not set]
  • Website: [not set]
  • Location: [not set]
  • About Me: [not set]

Recent Comments

  • The WPF Tab Control - Inside and Out
    07/29/2010 - 03:28

    I had the same thing a few weeks back and your on the right path. The code block below is the code I used to apply the style to all my tabs. Note that I don't think that this is perfect, as you'll still need to set a min width to ensure the tabs don't wrap badly (plus I had to do some hacking to get the tabs to overlap properly), but should give you a good starting point at the very least.

    Enjoy, Stewy

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Style TargetType="{x:Type TabControl}">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="8"></ColumnDefinition>
                                <ColumnDefinition></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="22"></RowDefinition>
                                <RowDefinition Height="*"></RowDefinition>
                            </Grid.RowDefinitions>
                            <TabPanel Grid.Column="1" Grid.Row="0" IsItemsHost="True"></TabPanel>
                            <ContentPresenter Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" ContentSource="SelectedContent" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style>
                        <Setter Property="Control.Height" Value="20"></Setter>
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type TabItem}">
                                    <Grid Grid.Column="1" Height="20">
                                        <Path Data="M0,0 C0,0 6,20 10,20 H100 C100,20 104,20 110,0 H0 " Margin="-8 0 0 0" Fill="LightGray" Grid.Column="0" StrokeLineJoin="Round" Stroke="DarkGray"></Path>
                                        <Path Data="M10,20 H100" Stroke="DarkGray" StrokeThickness="2" Margin="-8 0 0 0" ></Path>
                                        <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Margin="-8 0 0 0"  Grid.Column="0" ContentSource="Header" />
                                    </Grid>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Trigger.Setters>
                                                <Setter Property="Background" Value="Beige"></Setter>
                                                <Setter Property="Panel.ZIndex" Value="1"></Setter>
                                            </Trigger.Setters>
                                        </Trigger>
                                        <Trigger Property="IsSelected" Value="false">
                                            <Trigger.Setters>
                                                <Setter Property="Background" Value="LightGray"></Setter>
                                            </Trigger.Setters>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>

  • The WPF Tab Control - Inside and Out
    07/29/2010 - 03:25

    To those looking to change the style of the font of a tab, you can perform the below change. Basically you surround the ContentPresenter with a TextBlock, and assign it a x:Name. you can then reference this in the Trigger section of the code. The font colour, size etc will cascade down to the actual text. Note that this may be overridden by overall text styling you may be applying at a global level.

    <ControlTemplate TargetType="{x:Type TabItem}">
        <TextBlock x:Name="textItemGrid">
            <ContentPresenter VerticalAlignment="Center" Margin="5 0 5 0" HorizontalAlignment="Center" ContentSource="Header" />
        </TextBlock>
        <ControlTemplate.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Trigger.Setters>
                    <Setter Property="Foreground" TargetName="textItemGrid" Value="Purple"></Setter>
                    <Setter Property="FontSize" TargetName="textItemGrid" Value="20"></Setter>
                    <Setter Property="Panel.ZIndex" Value="1"></Setter>
                </Trigger.Setters>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>