XAML Issue with Gestures on controls bound to objects of MVVM (Sample project included)

LyndonHugheyLyndonHughey USUniversity ✭✭✭

I'm having an issue where GestureRecognizers in XAML pages aren't firing when their containing control is bound to an object of a ViewModel. It seems as if setting the BindingContext of a label to an object breaks the GestureRecognizers bound to that label. Note that this issue only occurs when the bindingContext is set to a child object of the VM, and the Text is set to a property of the bound child object. It does not occur when the Text bound to a direct property of the VM or with static text. Also, this issue does not occur with cs files.

I've created a sample project which illustrates the issue. The project contains two pages. One is a XAML page, the other is a CS page. Both pages contain three labels a gestureRecognizer attached to each label.

The first label has hard coded text. Xaml: Works CS: Works
The second label is bound to a Employee object within the VM, and text displays the Phone property of the Employee object. Xaml: Doesn't fire CS: Works
The third label is bound to a property of the VM. Xaml: Works CS: Works

Notes:
This has only been tested on ios 9.2
I am using Xlabs.Form's MVVM (version 2.0.5782)
I'm using the latest stable Xamarin nuget packages

Thanks for your help!

Best Answer

Answers

  • LyndonHugheyLyndonHughey USUniversity ✭✭✭

    Thank you, for the detailed response Adam. Its working working as expected now that i've corrected the code.

Sign In or Register to comment.