I tried out the new gesture recognizer functionality on Spans that's part of 3.2. When binding to an ICommand from the Command property of a TapGestureRecognizer, the ICommand isn't executed when a tap occurs. This is true for both XAML and C# implementations.
<Span Text="default, " Style="{DynamicResource BodyStyle}">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapCommand}" />
</Span.GestureRecognizers>
</Span>
var span = new Span { Text = "default, " };
var tapGesture = new TapGestureRecognizer();
tapGesture.SetBinding(TapGestureRecognizer.CommandProperty, "TapCommand");
span.GestureRecognizers.Add(tapGesture);
formattedString.Spans.Add(span);
The TapGestureRecognizer detects the tap and calls the execute delegate of the bound ICommand, which displays an alert.
Nothing happens.
Linking another issue I found
https://github.com/xamarin/Xamarin.Forms/issues/2892
In case the fix turns out to be related
This is also happening to all my Xamarin Forms Apps (v3.4.x, Android, UWP, and iOS). The attached TapGestureRecognizer in the spans do not work.
I've encountered this issua a while ago and now tried again (forgot it was a thing) and happen to "discover" a way to make it work and probably a hit why it happens in the first place
this code won't work and the command won't be triggered
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding Word.Noun, StringFormat='{0} (n.)'}">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding PronounceWordCommand}" CommandParameter="{Binding .}" />
</Span.GestureRecognizers>
</Span>
<Span Text="
" />
<Span Text="{Binding Word.Adjective, StringFormat='{0} (adj.)'}">
<Span.GestureRecognizers>
<TapGestureRecognizer Command="{Binding PronounceWordCommand}" CommandParameter="{Binding .}" />
</Span.GestureRecognizers>
</Span>
</FormattedString>
</Label.FormattedText>
</Label>
but, changing the binding from "." to the actual text makes it work!
<TapGestureRecognizer Command="{Binding PronounceWordCommand}" CommandParameter="{Binding Word.Adjective}" />
Has anyone tested a Span with a TapGestureRecognizer on iOS in Landscape orientation? It doesn't seem to be working as expected.
when text direction is RTL command takes more than one tap to execute?
Has anyone tested a Span with a TapGestureRecognizer on iOS in Landscape orientation? It doesn't seem to be working as expected.
I'm observing this issue on a iPad. TapGestureRecognizer works when the device is in Portrait mode, but not when it is in Landscape mode. Odd indeed.
Observed with Xamarin Forms version 4.2.709249.
Seems related to this #4143