Get ListView Item Values of row tapped

Viewed 410

Get ListView Item Values of row tapped. I am able to get the item tapped in code behind like so:

private async void Item_Tapped(object sender, ItemTappedEventArgs e)
{
    ListView listView = (ListView)sender;
    if (listView != null)
    {
       string pName = e.Item //.PNname; **<<-- This is returning my bound values (4 items) as PName, PNumber... and so on**
    }
}

I try to type the .PName it is a sub value to the e.Item list but that is invalid. I really need to grab by name because it appears the return selected row item returns values in a random way? One time PName will be first then next it might be 2nd or 3rd?

Anyway what am I missing to grab the values I need?

I'm doing a lot more visual things here but wanted to keep this code very simple to what I am actually having an issue with getting the individual values in the row.

TIA! Cheers! Rick...

2 Answers

e.Item is an object (datatype), if I am not mistaken. You have to cast e.Item to the right data type first:

string pName = (e.Item as Person)?.PName;

(assuming that PName is a property of the class Person)

Try get the itemIndex clicked and get the element in the list or use the AutomationId.

Related