I'm not sure if this is just the default WPF tab management behavior or if there is a way to disable it.
I have a tab control that is defined below:
<TabControl TabStripPlacement="Left" Background="Transparent" ItemsSource="{Binding Path=AvailableProducts}" SelectedValuePath="Name" SelectedValue="{Binding Path=SelectedProduct, Mode=TwoWay}">
AvailableProducts is a list of products. For instance:
Foo Bar Baz
SelectedProduct is initially null , but when the tab control is displayed, it automatically selects Foo . I want no tab to be selected at all.
Will the tab control always select the first tab?
UPDATE
I have added some sample code that shows what I am describing.
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <TabControl SelectedIndex="1"> <TabItem Header="TAB 1"> <Button>TEST</Button> </TabItem> <TabItem Header="TAB 2"> <TabControl TabStripPlacement="Left" Background="Transparent" ItemsSource="{Binding Path=AvailableProducts}" SelectedValuePath="Name" SelectedValue="{Binding Path=SelectedProduct, Mode=TwoWay}"/> </TabItem> </TabControl> </Grid> </Window> using System.Collections.Generic; namespace WpfApplication1 { public partial class MainWindow { private List<Product> _availableProducts = new List<Product>(); public MainWindow() { SelectedProduct = null; InitializeComponent(); _availableProducts.Add(new Product("Foo")); _availableProducts.Add(new Product("Bar")); _availableProducts.Add(new Product("Baz")); DataContext = this; } public List<Product> AvailableProducts { get { return _availableProducts; } } public string SelectedProduct { get; set; } } public class Product { public Product(string name) { Name = name; } public string Name { get; set; } public override string ToString() { return Name; } } }
If you run the above code, the application will start showing up with βTAB 2β and none of the Foo / Bar / Baz tabs will be selected. However, if you change
<TabControl SelectedIndex="1">
to
<TabControl SelectedIndex="0">
and run the application, it starts with "TAB 1", and when you switch to "TAB 2", the first tab (Foo) is selected.
I donβt understand why, if you start βTAB 2β, it works as I expect, but if you start βTAB 1β and then switch to βTAB 2β, the tab is selected by default.