, , .
I have only a few ListView controls (two or three), so I can do the following.
ListViewItem listViewItem = e.OriginalSource as ListViewItem;
if (listViewItem == null)
{
...
}
else
{
if (firstListView.ItemContainerGenerator.IndexFromContainer(listViewItem) >= 0)
{
...
}
else if (secondListView.ItemContainerGenerator.IndexFromContainer(listViewItem) >= 0)
{
...
}
}
This can be used with a foreach loop, but if there are hundreds of ListView controls to iterate, then finding the parent ListView in the ListViewItem is probably more efficient (like most other answers). However, I find that my solution is cleaner (a bit). Hope this helps someone!
source
share