I installed the Xamarin community toolkit, and I am trying to play a message to the user when long pressing the item, but for some reason, it doesn't trigger. I want to send the selected item as a parameter, and delete it I added a little portion of the ViewModel, and the binding context is set in code behind
<ContentPage.Content>
<ListView x:Name="CarsList"
Grid.Row="1"
SeparatorVisibility="Default"
ItemsSource="{Binding Cars}"
HasUnevenRows="True"
SelectionMode="None"
SelectedItem="{Binding SelectedCar}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell xct:TouchEffect.Command="{Binding Source={x:Reference ListPage}, Path = BindingContext.PressedCommand}"
xct:TouchEffect.CommandParameter="{Binding .}">
<local:CarView Padding="0,10,0,0" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
public Command PressedCommand
{
get; set;
}
public SampleViewModel()
{
PressedCommand = new Command(PressAction);
GridSpan = Device.Idiom == TargetIdiom.Phone ? 1 : 2;
BuildCars();
}
private void PressAction(object obj) => throw new NotImplementedException();
private void LongAction(object obj)
{
Application.Current.MainPage.DisplayAlert("Warning", "do you want to delete?", "OK");
}
.....
private ObservableCollection<Car> _cars;
public ObservableCollection<Car> Cars
{
get
{
return _cars;
}
set
{
SetProperty(ref _cars, value);
}
}
}