Keep TabItems in TabControl from being re-placed?

In WPF: Is there an easy way to stop TabItems in a TabControl from overriding when the selected TabItem changes? To have a click on a TabItem just display its contents, but not rearrange the TabItems as usual (moving the selected TabItem to the bottom row of tabs if it isn't already there).

Edit. To clarify, I want the tabs to appear on multiple lines, I just don't want the tab headers to be rearranged when a TabItem is selected from a row other than the bottom row. I would like the collection of titles to remain completely static, but the contents of this TabItem are still displayed when the title is clicked.

Thanks!

+2


a source to share


2 answers


I know him late, but I had to figure it out today, so here goes.

Basically you need to create your own control template for the tab control and use a different panel to contain the tabs.

Here's a simplified example using WrapPanel.

<Style TargetType="TabControl" x:Key="MyTabControl">
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="TabControl">
      <Grid SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local" HorizontalAlignment="Stretch">
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <WrapPanel x:Name="HeaderPanel" HorizontalAlignment="Center" VerticalAlignment="Top" IsItemsHost="true"
            Grid.Row="0" KeyboardNavigation.TabIndex="1" />
        <ContentPresenter Grid.Row="1" x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="10" />
      </Grid>
    </ControlTemplate>
  </Setter.Value>
</Setter>

      



Then you use it like this

 <TabControl Style="{StaticResource MyTabControl}" ....

      

You can download control template samples here

+5


a source


If you have Blend you can edit the template copy for the tab control to remove this behavior, I believe.



0


a source







All Articles