0

In WPF i have a TabControl and i've attached it a SelectionChanged event handler: when i select a TabItem i load some data in a DataGrid.

The problem is that if i click on some row in the DataGrid, wpf call again the TabControl SelectionChanged. How can i deny that wpf call this event when i click on a row in the datagrid?

I've tried to identify the sender but doesn't work:

private void TabControl_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
   if(sender is TabControl){
     .....
     .....
    }
}

if i click on a row in the datagrid, it's called this handler and the sender is a TabControl. I don't understand why!!!

Tom
  • 4,007
  • 24
  • 69
  • 105
  • I'm not sure why it is triggering again, but could you just save the sender off in some variable and compare against it (instead of doing the is check)? – BradleyDotNET Mar 17 '14 at 20:51
  • I must create a SelectionChanged event handler also for the DataGrid and type the code: e.Handled = true ?!! – Tom Mar 17 '14 at 20:52
  • I'm sorry, I'm not sure what impact that code has on the tab control selection changed? – BradleyDotNET Mar 17 '14 at 20:53
  • I think that the SelectionChanged propagate up to the Control: so if it's not handled by the datagrid, the signal SelectionChanged goes up to the TabControl parent Control – Tom Mar 17 '14 at 20:54
  • What do you want `SelectionChanged` for? – Federico Berasategui Mar 17 '14 at 20:54

0 Answers0