I follow the example of ListView Context Actions
https://developer.xamarin.com/guides/xamarin-forms/user-interface/listview/interactivity/#Context_Actions
to use swip-to-delete feature
<ListView x:Name="lvElectricianList" RowHeight="50" ItemTapped="lvElectricianList_ItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" Clicked="MenuItem_Clicked" />
</ViewCell.ContextActions>
<StackLayout Orientation="Horizontal">
<StackLayout Orientation="Vertical" HorizontalOptions="CenterAndExpand">
<Label Text="{Binding Name}" Font="20" FontAttributes="Bold" />
<StackLayout Orientation="Horizontal">
<Label Text="Nickname:" Font="14" />
<Label Text="{Binding Nickname}" Font="14"/>
</StackLayout>
</StackLayout>
<Label Text="› " Font="30" FontAttributes="Bold" VerticalTextAlignment="Center" HorizontalOptions="End" TextColor="Green" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
But the behind event code
private void MenuItem_Clicked(object sender, EventArgs e)
{
MenuItem mi = (MenuItem)sender;
Electrician selectedElectrician = ((Electrician)mi.CommandParameter);
.......
}
Visual Studio 2015 says the following error message:
Severity Code Description Project File Line Suppression State
Error CS1061 'MenuItem' does not contain a definition for 'CommandParameter' and no extension method 'CommandParameter' accepting a first argument of type 'MenuItem' could be found (are you missing a using directive or an assembly reference?)
According to Xamarin, Xamarin.Forms.MenuItem Class has CommandParameter as its public property
https://developer.xamarin.com/api/type/Xamarin.Forms.MenuItem/
But VS2015 can't recognize it and it can't be built. Please help to solve the problem. Thanks