Is there a way to get the ListViewItem container when a ListViews selection has changed. I've tried using 
listView.ItemContainerGenerator.ContainerFromItem(listView.SelectedItem);
from the ListViews selection changed event but this always returns null. Any ideas what I'm doing wrong?
XAML:
<ListView ItemsSource="{x:Bind RowItems}"
              SelectionChanged="ListView_OnSelectionChanged"/>
Code-behind:
private void ListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var item = e.AddedItems?.FirstOrDefault();
    // edit: also get container
    var container = ((ListViewItem) (listView.ContainerFromItem(item)));
}
Note that listView.ItemContainerGenerator.ContainerFromItem is obsolete since Windows 8.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With