Created
March 23, 2022 04:16
-
-
Save emoacht/c48d0b03cf28056756167ba433b387a6 to your computer and use it in GitHub Desktop.
Get index number of ListViewItem in ListView.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListViewHelper | |
{ | |
public static int GetIndex(object item) | |
{ | |
if (item is not ListViewItem listViewItem) | |
return -1; | |
ListView listView = (ListView)ItemsControl.ItemsControlFromItemContainer(listViewItem); | |
return listView.ItemContainerGenerator.IndexFromContainer(listViewItem); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment