Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

align wpf tabcontrol strip

I'm trying to align a tabcontrol strip on the right.

Just to be clear - I want the tabs on the top (tabstripplacement), but aligned on the right.

like image 541
mson Avatar asked Jan 26 '11 00:01

mson


2 Answers

The Headers for the TabItem's are located in a panel of type TabPanel. We can add HorizontalAlignment="Right" for it in the Resources of TabControl

<TabControl ...>
    <TabControl.Resources>
        <Style TargetType="TabPanel">
            <Setter Property="HorizontalAlignment" Value="Right"/>
        </Style>
    </TabControl.Resources>
    <!--...-->
</TabControl>
like image 165
Fredrik Hedblad Avatar answered Sep 22 '22 14:09

Fredrik Hedblad


I don’t know why, but ItemsPanel replacement doesn’t work. You must replace template for whole TabControl:

<TabControl ItemsSource="{Binding Items}">
    <TabControl.Template>
        <ControlTemplate TargetType="TabControl">
            <DockPanel LastChildFill="True">
                <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Right" IsItemsHost="true"/>
                <ContentPresenter ContentSource="SelectedContent"/>
            </DockPanel>
        </ControlTemplate>
    </TabControl.Template>
    <!-- This XAML doesnt work!-->
    <!--<TabControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel HorizontalAlignment="Right" IsItemsHost="True"/>
        </ItemsPanelTemplate>
    </TabControl.ItemsPanel>-->
</TabControl>
like image 43
SeeSharp Avatar answered Sep 25 '22 14:09

SeeSharp