Xamarin Forms: DataTemplate Command Binding not working

TF 96 Reputation points
2021-05-13T07:26:19.073+00:00

I have the following carousel view on my Xamarin Forms page (named page)
<CarouselView x:Name="carousel"
ItemsSource="{Binding Videos}"
HeightRequest="215">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Image
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
HeightRequest="200"
CacheDuration="7"
CacheType="Disk"
DownsampleToViewSize="True"
Source="{Binding ThumbnailUrl}">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding BindingContext.PlayVideoCommand, Source={x:Reference page}}" CommandParameter="{Binding VideoUrl}"/>
</Image.GestureRecognizers>
</Image>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>

and my command:
public ICommand PlayVideoCommand => new Command<Video>(async (x) =>
{
//
});

However, my command on my viewmodel is never fired when I tap the image

Developer technologies .NET Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. TF 96 Reputation points
    2021-05-13T07:53:24.88+00:00

    I've sorted it. I was pushing through a url and expecting a Video object...

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.