Tab SelectionChanged fired despite no change in TabItem selected

Hi,
My question is this. I have a tab control which hosts a listbox and a combobox on separate tabs. I have SelectionChanged events hooked to the three controls : tabcontrol, listbox and combobox.

As I change tab, as expected, the tabSelChanged is fired. Now, the weird thing is, if I were to change my selection of either the listbox or the combobox - not only the corresponding events for the controls are being fired (listboxSelChanged / comboSelChanged), the tabSelChanged is also fired although there is no change in the selected tab. I was expecting that tabSelChanged to be fired only when different tabItem is selected.

Anyone care to shed some light on this behavior? Thank you.

Code Snippet

<Grid x:Name="LayoutRoot">
<TabControl IsSynchronizedWithCurrentItem="False" SelectionChanged="tabSelChanged">
<TabItem Header="TabItem1">
<Grid>
<ListBox HorizontalAlignment="Left" Margin="139,62.723,0,160" Width="112" IsSynchronizedWithCurrentItem="False" SelectionChanged="listboxSelChanged">
<ListBoxItem Content="ListBoxItem1"/>
<ListBoxItem Content="ListBoxItem2"/>
<ListBoxItem Content="ListBoxItem3"/>
</ListBox>
</Grid>
</TabItem>
<TabItem Header="TabItem2">
<Grid>
<ComboBox Width="100" Height="30" IsSynchronizedWithCurrentItem="False" SelectionChanged="comboSelChanged">
<ComboBoxItem Content="ComboBoxItem1"/>
<ComboBoxItem Content="ComboBoxItem2"/>
<ComboBoxItem Content="ComboBoxItem3"/>
</ComboBox>
</Grid>
</TabItem>
</TabControl>
</Grid>

private void tabSelChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
Debug.Print("MainTab");
}

private void comboSelChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
Debug.Print("MainCombo");
}

private void listboxSelChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
Debug.Print("MainListBox");
}


[2550 byte] By [szl] at [2008-1-7]
# 1

its handled property is not set to true, so the handlers that listen to that are invoked

set e.Handled=true;

leed at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
Ok, I got what u mean. Thank you very much.
szl at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified