Assume we have a data grid with a binding to an ItemSource collection. We would like to add a column with the index number.
First, add the AlternationCount binding:
<DataGrid
...
ItemsSource="{Binding MyObservableCollection}"
AlternationCount="{Binding MyObservableCollection.Count}"
...
/>
Now add the data grid column with binding to the alternation inded
<DataGridTextColumn Binding="{Binding AlternationIndex, RelativeSource={RelativeSource AncestorType=DataGridRow}}" Header="#" FontSize="20"/>
Tags
WPF