In Xamarin Forms, I defined a custom data template like so:
<DataTemplate x:Key="MyControlDataTemplate">
<ViewCell>
<controls:MyControl/>
</ViewCell>
</DataTemplate>
This snippet belongs to a ListView
in MainPage.xaml
which has its binding context set to MainPageViewModel.cs
Inside MyControl
, I want to bind to a property of MainPageViewModel
.
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{set binding here to MainPageViewModel property}" />
</Label.GestureRecognizers>
MainPageViewModel
has this command property:
public Command<MyItem> LabelTappedCommand { get; set; }
The idea is to create a single Command
object which gets shared between each cell by also setting the CommandParameter
property, but I'm stuck with the Command
property right now.
Is this possible?