I have a listView created in xaml like so:
<ListView x:Name="AccountsList" ItemSelected="AccountSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnEdit"
Text="Edit" />
<MenuItem Clicked="OnDelete"
Text="Delete" IsDestructive="True" />
</ViewCell.ContextActions>
<ViewCell.View>
<StackLayout Orientation="Vertical"
HorizontalOptions="StartAndExpand">
<Label Text="{Binding DeviceName}"
HorizontalOptions="CenterAndExpand"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I'm assigning the ItemSource programmatically like so:
AccountsList.ItemsSource = App.Database.GetAccounts ();
And here's my 'onDelete' method:
public void OnDelete (object sender, EventArgs e) {
var mi = ((MenuItem)sender);
DisplayAlert("Delete Context Action", mi.Command + " delete context action", "OK");
}
I want to be able to reference the 'DeviceName' of the object from the 'onDelete' method. I know I can do this with the 'AccountSelected' method like this:
void AccountSelected(object sender, SelectedItemChangedEventArgs e)
{
var _account = (Account)e.SelectedItem;
// And access the account here.
}
But the 'Clicked' method doesn't allow a 'void OnDelete (object sender, SelectedItemChangedEventArgs e)' signature (and I doubt it work work anyways).
How can I accomplish this?