WPF ItemsControl the current ListItem Index in the ItemsSource

后端 未结 5 1016
旧时难觅i
旧时难觅i 2020-12-05 11:10

Is it possible to know the current item\'s Index in a ItemsControl?

EDIT This works!



    

        
5条回答
  •  庸人自扰
    2020-12-05 11:52

    Yes it is! ItemsControl exposes an ItemContainerGenerator property. The ItemContainerGenerator has methods such as IndexFromContainer which can be used to find the index of a given item. Note that if you bind your ItemsControl to a collection of objects, a container is automatically generated for each. You can find the container for each bound item using the ContainerFromItem method.

提交回复
热议问题