In WPF, Is there a simple way to stop TabItems in a TabControl from being repositioned when the selected TabItem changes? So that clicking on a TabItem would simply display its contents, but not reposition the TabItems as it usually does (by moving the selected TabItem to the bottom row of tabs if it wasn't there already).
Edit: To clarify, I do want the tabs to be displayed in multiple rows, I just don't want the tab headers to be repositioned when a TabItem from a row other than the bottom row is selected. I'd like the collection of headers to remain completely static, but for the contents of that TabItem to still be displayed when its header is clicked.
Thanks!
I know its late but I had to figure this 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 your tab items.
Here is a simplified example using a 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>
You then use this as follows
<TabControl Style="{StaticResource MyTabControl}" ....
You can download the control template samples here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With