简体   繁体   中英

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?

why happen this?

Because SelectionChanged is a routed event.

Routed Events Overview: https://docs.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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM