RoutedEventArgs.Source vs Sender

前端 未结 4 1072
执念已碎
执念已碎 2020-12-05 11:44

What is the difference between sender and source in wpf event handling?

For example, say I had an ellipse in a canvas, and clicked on the ellipse:

4条回答
  •  旧时难觅i
    2020-12-05 12:39

    Bubbles!

    The sender is the object that the event is being raised from, whereas source was the original element that is causing the event to be raised.

    Like in this case:

    
        
            
                
                
            
        
        
    
    
    private void tc1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    }
    

    In this case, if you change the SelectedItem on the Sub-TabControl, sender will equal tc1, Source will equal tc2.

提交回复
热议问题