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

Bug in SelectionChanged event

4 Answers 210 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Serhiy
Top achievements
Rank 1
Serhiy asked on 09 Oct 2009, 08:37 PM
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.

<UserControl  
    x:Class="TestSilverlightApplication.Page" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:radInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" 
    > 
 
    <Grid Background="White">  
        <Grid.RowDefinitions> 
            <RowDefinition Height="Auto" /> 
            <RowDefinition Height="*" /> 
        </Grid.RowDefinitions> 
          
        <radInput:RadTabControl Grid.Row="0" Name="tabControl">  
            <radInput:RadTabItem Header="Tab 1">  
                <radInput:RadTabControl> 
                    <radInput:RadTabItem Header="Tab 1.1" /> 
                    <radInput:RadTabItem Header="Tab 1.2" /> 
                </radInput:RadTabControl> 
            </radInput:RadTabItem> 
 
            <radInput:RadTabItem Header="Tab 2">  
                <radInput:RadTabControl> 
                    <radInput:RadTabItem Header="Tab 2.1" /> 
                    <radInput:RadTabItem Header="Tab 2.2" /> 
                </radInput:RadTabControl> 
            </radInput:RadTabItem> 
        </radInput:RadTabControl> 
 
        <TextBox Grid.Row="1" Name="logTextBox" AcceptsReturn="True" /> 
 
    </Grid> 
</UserControl> 
using System;  
using System.Windows;  
 
namespace TestSilverlightApplication  
{  
    public partial class Page  
    {  
        public Page()  
        {  
            InitializeComponent();  
 
            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 ?

4 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav
Telerik team
answered on 12 Oct 2009, 06:32 AM
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
(OnSelectionChanged));

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,

Regards,
Miroslav
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.
0
Chris Miskowiec
Top achievements
Rank 1
answered on 04 Mar 2010, 10:34 PM
Miroslav,

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?
0
Miro Miroslavov
Telerik team
answered on 09 Mar 2010, 10:44 AM
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.
0
Chris Miskowiec
Top achievements
Rank 1
answered on 09 Mar 2010, 03:22 PM
Thanks for the explanation.
Tags
TabControl
Asked by
Serhiy
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Chris Miskowiec
Top achievements
Rank 1
Miro Miroslavov
Telerik team
Share this question
or