I am trying to display an action sheet from the viewmodel when the user taps on an Item in the ListView using commanding. Currently I have this in my Xaml. But I get a compiler error message stating that Event ItemTapped can only be bound to properties of delegate type EventHandler
<ListView x:Name="listView" ItemsSource="{Binding CustomerList}" FlexLayout.Grow="1" HasUnevenRows="True" ItemTapped="{Binding LVItemTappedCommand}" >
This is the Method in my ViewModel
[RelayCommand]
private void LVItemTapped()
{
// Handle the tapped item here
}
This is how it looks in the code behind but since I am using MVVM I only want code in my ViewModel
private async void listview_ItemTapped(object sender, ItemTappedEventArgs e)
{
var customer = (Customer)e.Item;
var action = await DisplayActionSheet("Action", "Cancel", null, "Edit", "Delete");
switch (action)
{
case "Edit":
_editCustomerId = customer.Id;
//nameEntryField.Text = customer.customer_name;
//emailEntryField.Text = customer.Email;
//mobileEntryField.Text = customer.Mobile;
break;
case "Delete":
//await _dbService.Delete(customer);
//listView.ItemsSource = await _dbService.GetCustomers();
break;
}
}