Bug in SelectionChanged event

5 posts, 1 answers
  1. Serhiy
    Serhiy avatar
    9 posts
    Member since:
    Jul 2008

    Posted 09 Oct 2009 Link to this post

    Looks like there's a bug in 2009.2.812.1030 build.
    It raises SelectionChanged event for tab control if selection changed in child tab control.

        <Grid Background="White">  
                <RowDefinition Height="Auto" /> 
                <RowDefinition Height="*" /> 
            <radInput:RadTabControl Grid.Row="0" Name="tabControl">  
                <radInput:RadTabItem Header="Tab 1">  
                        <radInput:RadTabItem Header="Tab 1.1" /> 
                        <radInput:RadTabItem Header="Tab 1.2" /> 
                <radInput:RadTabItem Header="Tab 2">  
                        <radInput:RadTabItem Header="Tab 2.1" /> 
                        <radInput:RadTabItem Header="Tab 2.2" /> 
            <TextBox Grid.Row="1" Name="logTextBox" AcceptsReturn="True" /> 
    using System;  
    using System.Windows;  
    namespace TestSilverlightApplication  
        public partial class Page  
            public Page()  
                tabControl.SelectionChanged += tabControl_SelectionChanged;  
            private void tabControl_SelectionChanged(object sender, RoutedEventArgs e)  
                logTextBox.Text += "SelectionChanged" + Environment.NewLine;  

    Click "Tab 1.1" -> "Tab 1.2" it still raises SelectionChanged for the parent tab control.

    Any thoughts ?
  2. Answer
    Miroslav avatar
    922 posts

    Posted 12 Oct 2009 Link to this post

    Hi Serhiy,

    I must admit that this may be a bit confusing but it is the expected behavior.

    The events that are exposed as standard CLR events in the Telerik controls are in fact wrappers over routed events. The routed events can be handled in any of the visual ancestors of the control.

    For example all TabControl.SelectionChanged events can be handled at the root of the application by using:

    appRoot.AddHandler(RadTabControl.SelectionChangedEvent, new RoutedEventHandler

    When you register for the Selection changed event, you actually register a handler for the routed event and therefore you receive the event from the inner control as well.

    In this case you can decide to handle the event before it reaches the outer TabControl (set e.Handled = true) or check the sender in the handler to distinguish between the two controls.

    Routed events can be very useful but in this case a bit confusing,

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Chris Miskowiec
    Chris Miskowiec avatar
    2 posts
    Member since:
    Mar 2010

    Posted 04 Mar 2010 Link to this post


    I am having the same problem but your solution does not help.  I am using build 2009.3.1208.1030.

    The problem is that RadTabControl.SelectionChanged uses a System.Windows.RoutedEventHandler.  The System.Windows.RoutedEventArgs class does not have the Handled property you indicated in your response.  Further, the sender in the handler always refers to the current RadTabControl, not the control which initiated the event.  Also, the RoutedEventArgs.OriginalSource property which is supposed to contain the event initiator is always null.

    Finally, to make matters worse, the AddHandler method you demonstrated also will not work, because AddHandler expects a System.Windows.RoutedEvent as the first argument, but RadTabControl.SelectionChangedEvent is a Telerik.Windows.RoutedEvent.  Thus that line of code cannot compile.

    Currently I cannot find any way to distinguish which tab control's selection has been changed, aside from writing my own custom code to keep track of it.

    Is this a bug after all, or am I missing something?
  4. Miro Miroslavov
    Miro Miroslavov avatar
    588 posts

    Posted 09 Mar 2010 Link to this post

    Hello Chris Miskowiec,

    The real object that is passed to RadTabControl.SelectionChanged is of type RadRoutedEventArgs, so you have to explicitly cast to this type and after that handle the event like rargs.Handled = true.
    The AddHandler method in that case is extension method in the class Telerik.Windows.DependencyObjectExtensions.

    Sorry for the inconvenience. Please let us know if you have further questions.

    Kind regards,
    Miro Miroslavov
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  5. Chris Miskowiec
    Chris Miskowiec avatar
    2 posts
    Member since:
    Mar 2010

    Posted 09 Mar 2010 Link to this post

    Thanks for the explanation.
Back to Top