WPF ItemsControl the current ListItem Index in the ItemsSource

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

<TextBlock Text="{Binding 
    RelativeSource={RelativeSource Mode=TemplatedParent}, 
    StringFormat={}Index is {0}}" />

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

Leave a Comment