This is a migrated thread and some comments may be shown as answers.

Event SelectionChanged not work correctly

6 Answers 189 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
En
Top achievements
Rank 1
En asked on 12 Apr 2013, 10:11 AM
Hello telerik team,
I got 2 TabControl name is tabMaster and tabChild.
tabMaster include 2 TabItem, and content of TabItem 1 is tabChild.
tabChild include 2 or more TabItem.
The problem is when i handler tabMaster.SelectionChanged and do change selection of tabChild, this handler to be called?

XAML code like this:
<telerik:RadTabControl x:Name="tabMaster">
            <telerik:RadTabItem Header="Tab-Master0">
 
                <telerik:RadTabControl x:Name="tabChild">
                    <telerik:RadTabItem Header="Tab-Child0" />
                    <telerik:RadTabItem Header="Tab-Child1" />
                    <telerik:RadTabItem Header="Tab-Child2" />
                </telerik:RadTabControl>
            </telerik:RadTabItem>
 
            <telerik:RadTabItem Header="Tab-Master1" />
        </telerik:RadTabControl>

Handler this on behind code:
Private Sub tabMaster_SelectionChanged(sender As Object, e As Telerik.Windows.Controls.RadSelectionChangedEventArgs) Handles tabMaster.SelectionChanged
 
End Sub
Looking your answer.
Thank,

6 Answers, 1 is accepted

Sort by
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 17 Apr 2013, 09:00 AM
Hi En,

The SelectionChanged is a bubble event. This is why you hear it (when it is fired from the inner RadTabControl ("tabChild")) in the parent control ("tabMaster"). In case that you want to restrict the bubbling you will have to handle the event. You have two options to properly do this.

The first option is to subscribe to both tabMaster.SelectionChanged and tabChild.SelectionChanged events and set the e.Handled property in the tabChild event handler to True.

The second option is to subscribe to the tabMaster.SelectionChanged event only. Please note that you will have to check the e.OriginalSource property. If the event is fired from the inner control ("tabChild") you will be allowed to cast that property to RadTabControl and its Name property will be "tabChild".

Is this what you were trying to ask? Is this information enough for you?

Don't hesitate to ask if you have any other questions.

Kind regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
En
Top achievements
Rank 1
answered on 18 Apr 2013, 07:32 AM
Hi Pavel,
The answer of your question is "Yes".
Thank for your help.
0
Joel Palmer
Top achievements
Rank 2
answered on 09 Nov 2015, 05:13 PM
My question is... should this be a "bubble event"?  My answer is... probably not.  I have the same scenario and it caused us a bug with some downtime.  When I have a ​tabMaster.SelectionChanged event handler, the source property comes back as "tabMaster" instead of the "tabChild".  How does this make any sense.  If it must continue to be a bubble event then at least tell us where the event originated.  This is unexpected behavior and has caused us some down-time and potential data loss.
0
Martin Ivanov
Telerik team
answered on 12 Nov 2015, 05:08 PM
Hi Joel,

The SelectionChanged event of RadTabControl is designed to work as the SelectionChanged events of the native WPF selectors as  ListBox and TabControl for example. Instead of SelectionChanged you can consider using the PreviewSelectionChanged event of RadTabControl which is tunneling routed event.

Also, you can check the event argument's Source and OriginalSource to find the control which triggers the event.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Joel Palmer
Top achievements
Rank 2
answered on 16 Nov 2015, 05:00 AM
I understand that you're not going to change the Architecture of this control for me.  But, it is a surprise how this works and I'm not the only to be surprised by it. 

Also, your second point about the Source isn't my experience.  I was capturing tabMaster events and the Source was tabMaster in this scenario... not tabChild.
0
Kiril Vandov
Telerik team
answered on 18 Nov 2015, 12:03 PM
Hello Joel Palmer,

The RadTabControl inherits from the MS Selector for WPF which is used for a base of the control. In the MS Selector for WPF the SelectionChanged event and other events are bubbling. In SL the RadTabContol inherits from a Selector which is Telerik.Windows.Controls.Selector, not the MS one as our implementation have features. The bubbling events provide the users to hear for them, not only from the control that they are fired and provides the users with a point of customization. For instance if you can have a custom logic for the Parent TabControl which will be triggered based on the selection made in the Inner TabControl. One of the reasons to implement our own Selector is that we are trying to provide the same functionality and experience for our clients for both the WPF and SL platforms. We can simply have bubbling event for WPF and non bubbling for SL, it will confuse our clients as they may have a working solution made for WPF and simply migrate it to SL, if there is a logic depending on the event routing it will be broken and the application will fail.

We have tested scenario with nested TabControls with our latest binaries and if you subscribe for the SelectionChanged event of Parent TabControl and its e.Source and e.OriginalSoruce in the selection changed event are always the Child TabControl if the selection is made by the child control. I have attached a sample project with two nested TabControls which works as expected on our side and the Source is as expected the child TabControl. If you are getting different Source could you please provide us with more details on the project and steps your are doing. Also if you could change the attached project to reproduce the issue on our side will help us further investigate.

I hope this information helps.

Kind regards,
Kiril Vandov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TabControl
Asked by
En
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
En
Top achievements
Rank 1
Joel Palmer
Top achievements
Rank 2
Martin Ivanov
Telerik team
Kiril Vandov
Telerik team
Share this question
or