Hi @Eduardo Gomez ,
Thanks for reaching out.
When you set:
<DataTemplate x:DataType="model:Contact">
the binding context inside that template becomes Contact. So x:Bind can only “see” members of Contact, not your FriendsPageViewModel. That’s why referencing the command directly doesn’t work.
Since you’re using [RelayCommand], the toolkit generates a property named OnContactTappedCommand. The key is making sure the template can access your page’s ViewModel.
Below is an approach you can consider:
- Give your Page a name and expose the ViewModel
<Page
x:Class="EasyShere.Views.FriendsPage"
x:Name="RootPage">
(Assuming you already have a ViewModel property set on the page.)
- Reference the ViewModel explicitly from the template
<interactivity:InvokeCommandAction
Command="{x:Bind RootPage.ViewModel.OnContactTappedCommand}"
CommandParameter="{x:Bind}" />
Here’s what’s happening:
-
RootPage.ViewModel.OnContactTappedCommandtellsx:Bindexactly where the command lives. -
CommandParameter="{x:Bind}"passes the currentContactitem to your command.
That way, when an item is tapped, your method:
void OnContactTapped(Contact contact)
will be called with the correct contact.
Take the code above as a reference and modify it to suit your project’s structure, naming conventions, and how you expose the ViewModel.
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.