Ilnumerouno
Ilnumerouno

Reputation: 65

SelectionChanged fired also on nested controls?

Sorry for misleading title, I'll try to explain better. I've a TabControl like this:

<dragablz:TabablzControl SelectionChanged="MainTabs_SelectionChanged" x:Name="MainTabs">

where inside I've different TabItems, I need to fire the event MainTabs_SelectionChanged each time the user change the TabItem, this working but the event is fired also when the selection of a combobox, available inside the tabitem, change.

This is the ComboBox:

<ComboBox Grid.Column="1" Grid.Row="1" ItemsSource="{Binding Groups}" 
                                              Margin="8,0,8,16" DisplayMemberPath="Name" SelectedItem="{Binding SelectedGroup}" />

why happen this?

Upvotes: 1

Views: 455

Answers (1)

mm8
mm8

Reputation: 169280

why happen this?

Because SelectionChanged is a routed event.

Routed Events Overview: https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/routed-events-overview

You could use the OriginalSource property to determine whether a tab was selected:

private void MainTabs_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.OriginalSource == MainTabs)
    {
        //do your thing
    }
}

Upvotes: 3

Related Questions