I have been working through many of the answers to the question about events and how they require a backing delegate field that will be used to store added callbacks. However, I am still extremely confused how that applies to the way I am implementing it. Below is the exact answer that I tried to follow and implement based on the question and answer, but to no avail.
https://stackoverflow.com/a/41641881/8065149
Overall, I am attempting to add custom gestures to a custom map render in Xamarin and Android. I want to be able to, on tap and hold, add a pin to my map. I have currently figured out how to add pins through a tap, but I want to change it to a long tap. Below is the tutorial that I have used to try to add gestures to my project, as it looked promising (even though his website isn't secure). And below the website is the github project as well in case that is easier to follow.
https://arteksoftware.com/gesture-recognizers-with-xamarin-forms/ https://github.com/RobGibbens/XamarinFormsGestureRecognizers
Below is the code in question. Specifically, the two lines if (this.GenericMotion != null)
and if (this.Touch != null)
. Both of those lines throw the error: The event 'View.GenericMotion' can only appear on the left hand side of += or -=
.
protected override void OnElementChanged (ElementChangedEventArgs<Label> e)
{
base.OnElementChanged (e);
if (e.NewElement == null) {
if (this.GenericMotion != null) {
this.GenericMotion -= HandleGenericMotion;
}
if (this.Touch != null) {
this.Touch -= HandleTouch;
}
}
if (e.OldElement == null) {
this.GenericMotion += HandleGenericMotion;
this.Touch += HandleTouch;
}
}
void HandleTouch(object sender, TouchEventArgs e)
{
_detector.OnTouchEvent(e.Event);
}
void HandleGenericMotion(object sender, GenericMotionEventArgs e)
{
_detector.OnTouchEvent(e.Event);
}
I attempted to follow the answer that I posted earlier, but I was confused about how I was supposed to check whether they were null or not, and then if they were how I as supposed to call the handlers that will actually work with the touch events.
If more code is required to shed some light on the problem please post a comment. Thank you.