align wpf tabcontrol strip

喜欢而已 提交于 2019-11-30 02:37:44

问题


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.


回答1:


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>



回答2:


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>


来源:https://stackoverflow.com/questions/4800455/align-wpf-tabcontrol-strip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!