Hello,
Xamarin support will end on May 1, 2024, it's recommended that you migrate your Xamarin app to .NET MAUI. Please see Xamarin official support policy .
If you want to get the selected Object in the ViewModel.
You can add the TapGestureRecognizer for your StackLayout
in the <ViewCell>
like following code.
<ListView x:Name="ChecklistView"
...
>
<ListView.ItemTemplate >
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding BindingContext.OnEditCommand, Source={x:Reference ChecklistView}}"
CommandParameter="{Binding .}"
/>
</StackLayout.GestureRecognizers>
Then, Open your CheckListPageModel
. Add ICommand interface and create a Command Object.
If you want to get current selected Object, please add an attribute in the OnEditCommandAction
method.
public ICommand OnEditCommand { get; set; }
public CheckListPageModel()
{
OnEditCommand = new Command(OnEditCommandAction);}
...
}
public void OnEditCommandAction(object SelectedObj)
{
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
**Note: Please follow the steps