Event Source Compared to Source

I am reading a C # WPF book and in the routed events chapter the event has 2 identical Source and OriginalSource properties. I did not see the difference between the two:

Xaml:

 <Button Name="Ok" Click="Ok_Click"/> 

Code behind:

 private void Ok_Click(object sender, RoutedEventArgs e) { bool flag = false; var source = e.Source; var originalSource = e.OriginalSource; if (source == originalSource) { flag = true; } } 

and flag property is true here, can anyone explain why 2 is the same property or in this case these properties have no effects? or where can we see a use case for these properties?

+6
source share
1 answer

A control can have other controls in it as child elements. When you subscribe to an event from a control, the parent you are subscribing to is likely to be e.Source , however, if the control has children and the child is the one who raised the event, then OriginalSource will be the child who raised the event.

In general, a subscription to a KeyDown event on a DataGrid . The source can be a grid, but the source can be a cell (or some component in a cell).

+10
source

Source: https://habr.com/ru/post/1214045/


All Articles