Is it possible to Left-Align headers in a WPF TabControl?

devuxer picture devuxer · Sep 22, 2009 · Viewed 10.2k times · Source

Right now, I have a WPF window where all the tab labels of the TabControl are centered.

I'd like the tab levels of the TabControl to be left-aligned.

Is this possible without completely redoing the ControlTemplate?

I tried messing with HorizontalAlignment, HorizontalContentAlignment, etc., but nothing I tried had the desired effect.

If I try this solution (offered by T Levesque):

<TabControl...>
    <TabControl.ItemContainerStyle>
        <Style TargetType="{x:Type TabItem}">
            <Setter Property="HorizontalAlignment" Value="Left"/>
        </Style>
    </TabControl.ItemContainerStyle>
    ...
</TabControl>

...I get this:

All the tab labels of the TabControl are left-aligned, but the tabs don't stretch properly

Which is close, but it ends up looking kind of like a histogram.

Answer

Reed Copsey picture Reed Copsey · Sep 22, 2009

The following will give you the look you are after.

    <TabControl TabStripPlacement="Left" HorizontalContentAlignment="Left" >
        <TabItem HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Header="Header 1">
            <TabItem.Content>Test</TabItem.Content>
        </TabItem>

        <TabItem HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Header="Header 2"  >
            <TabItem.Content>Test</TabItem.Content>
        </TabItem>

        <TabItem HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Header="Header Longer Version">
            <TabItem.Content>Test</TabItem.Content>
        </TabItem>
    </TabControl>