问题
I'm trying to use the OriginalSource property to determine the specific UIElement that generated a PointerReleased event. According to the documentation RoutedEventArgs.OriginalSource returns the object that originated the event but I don't know how to use that to identify the UIElement. I can use OrginalSource.ToString() to identify the type of UIElement but not a specific instance. My approach may be entirely wrong, if so, that would be worth knowing too. Thanks.
回答1:
If you have set of potential candidates to cross check against, you can simply do the equality check between original source and each potential candidate using ==
or using .Equals()
method of Object.
Secondly, in case you want original source to tell it's identity, what you can do is set x:Name
on control instance in XAML and then in code you can access Name
property to validate it's identity.
XAML:
<TextBlock x:Name="myTextBlock"/>
Code:
string sender = (e.OriginalSource as FrameworkElement).Name;
来源:https://stackoverflow.com/questions/26937434/how-can-routedeventargs-originalsource-property-be-used-to-identify-the-specific