Closed JanettHolst290490 closed 5 years ago
Something like this should work:
In the XAML:
<ContentPage
...
x:Name="myPage">
...
<TapGestureRecognizer
Command="{Binding BindingContext.TapCommand, Source={x:Reference myPage}}"
CommandParameter="{Binding .}" />
In your view model:
public MyViewModel()
{
TapCommand = new Command<MyUIModel>(TapCommandExecute);
}
public ICommand TapCommand { get; }
private void TapCommandExecute(MyUIModel param)
{
// your logic
}
Explanation:
Command="{Binding BindingContext.TapCommand, Source={x:Reference myPage}}"
As a source you take your myPage
object which is your Page
Page objects have BindingContext
which should be your MyViewModel
, so BindingContext.TapCommand
will point to your command on your VM
CommandParameter="{Binding .}"
will send the current BindingContext of the item on the list as a parameter to the command, so you need to make sure your command is a generic version with <T>
, where T
is your model you bind to the items, example new Command<MyUIModel>(TapCommandExecute)
Hope it helps :)
I had same problem @JanettHolst290490
I solved using
TapCommand = new Command(TapCommandExecute);
instead of
TapCommand = new Command<MyUIModel>(TapCommandExecute);
and on my xaml
<TapGestureRecognizer Command="{Binding BindingContext.TapCommand, Source={x:Reference MYPAGE}}" CommandParameter="{Binding .}" />
@JanettHolst290490 did you make it work? can we close the issue?
Yes I made it work. However I'm using FreshMvvm so the bindings are a bit different. But I resolved the issue by setting the Command on the Event Item's View model.
Thank you for the help, you guided me in the right direction.
Is it possible to click on an item in the list below and react on it ? I can't seem to find any examples on this. Something like this doesn't work:
How do I make an item clickable in the list in the bottom?