I'm writing an app for Android in Xamarin Forms. I want to navigate the user from one page to another, when user clicks an "EditList" button (middle one), but at the same time I want to pass an argument of specific type: "ShoppingList", which I get from ListView's ItemSelected event in order to display it's contents on the next Page.
The problem is - the only way I can get that value is when the item in listview is clicked. How can I get that listview item clicked value from within the button, without having to click on the listview item beforehand?
How it looks
Also here's the Page for reference. ListView with ShoppingList items
I'm using Navigation.PushAsync(), where I also pass a ShoppingListDetailViewModel and inject the item from SelectedItem
OnItemSelected
Here is ListView's OnItemSelected event handler for ItemSelected event:
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
{
var item = args.SelectedItem as ShoppingList;
if (item == null)
return;
await Navigation.PushAsync(new ShoppingListDetailPage(new ShoppingListDetailViewModel(item)));
// Manually deselect item.
ItemsListView.SelectedItem = null;
}
(ItemsListView is my ListView's name defined in XAML like that x:Name="ItemsListView")
I've tried to make Command which would maybe pass a Shopping List object through Command parameter but I got confused with all that, and I think that there must be simpler solution for doing this wich I just can't see.
XAML
This is my XAML Page with the ListView and button inside it: