Search code examples
c#xamarinxamarin.formsxamarin.androidxamarin.ios

Xamarin Forms ListView ItemTapped to object from ViewModel


I have a problem. I have created a ListView with an ItemSource from my ViewModel. Now the ItemSource is an ObservableCollection<KnownDevice> with a few objects called KnownDevice. In my ListView I have set: ItemTapped="rowDevice_Clicked" with the following function:

private void rowDevice_Clicked(object sender, ItemTappedEventArgs e)
{
    ListView listView= (ListView)sender;
}

But now I need to know which KnownDevice was clicked.

How can I do that?


Solution

  • add this line of code inside your rowDevice_Clicked

    var device = e.Item as KnownDevice