Event SelectionChanged not work correctly

7 posts, 1 answers
  1. En
    En avatar
    15 posts
    Member since:
    Nov 2011

    Posted 12 Apr 2013 Link to this post

    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,
  2. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 17 Apr 2013 Link to this post

    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.

  3. DevCraft banner
  4. En
    En avatar
    15 posts
    Member since:
    Nov 2011

    Posted 18 Apr 2013 Link to this post

    Hi Pavel,
    The answer of your question is "Yes".
    Thank for your help.
  5. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 09 Nov 2015 Link to this post

    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.
  6. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 12 Nov 2015 Link to this post

    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
  7. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 15 Nov 2015 Link to this post

    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.
  8. Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 18 Nov 2015 Link to this post

    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
Back to Top
DevCraft banner