You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Depending on what kind of gesture you use, if you listen for the event associated with the gesture (for example DragStarting or Tapped) you either get the GestureRecognizer as the sender or the view in which the GestureRecognizer is inside of.
This is not a bug - but it is inconsistent. For example, if I listen for the Tapped event, the sender is going to be the view. If I listen for drag-related events (DragStarting, DragOver, DragLeave), I will get the DragGestureRecognizer.
This means that in certain scenarios, you can just cast your sender as a View while in others you have to do (sender as Element).Parent if you want to access the view that sent the event.
A simple way to illustrate this is using a blank app pasting the following:
Put a break point in each method and observe who the sender is after a gesture is executed. When OnTap gets called, the sender will be the Label element. When OnDragStart is called, the sender will be the DragGestureRecognizer
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Depending on what kind of gesture you use, if you listen for the event associated with the gesture (for example DragStarting or Tapped) you either get the GestureRecognizer as the sender or the view in which the GestureRecognizer is inside of.
This is not a bug - but it is inconsistent. For example, if I listen for the
Tapped
event, thesender
is going to be the view. If I listen for drag-related events (DragStarting, DragOver, DragLeave), I will get theDragGestureRecognizer
.This means that in certain scenarios, you can just cast your
sender as a View
while in others you have to do(sender as Element).Parent
if you want to access the view that sent the event.A simple way to illustrate this is using a blank app pasting the following:
In the xaml:
In the code behind:
Put a break point in each method and observe who the
sender
is after a gesture is executed. WhenOnTap
gets called, the sender will be theLabel
element. WhenOnDragStart
is called, the sender will be theDragGestureRecognizer
Shouldn't this behavior be standardized?
Beta Was this translation helpful? Give feedback.
All reactions