WPF ItemsControl the current ListItem Index in the ItemsSource

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

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

EDIT This works!



    

        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 11:50

    I asked the same thing a while ago here

    There isn't a built in Index property, but you can set the AlternationCount of your ItemsControl to something higher than your item count, and bind to the AlternationIndex

    
    

    It should be noted that this solution may not work if your ListBox uses Virtualization as bradgonesurfing pointed out here.

提交回复
热议问题