I have a View and a Viewmodel.
The Viewmodel has a property of type ICollectionView
which I instance a CollectionViewSource
with the Source, which is an ObservableCollection<Foo>
Now on my view I have a Datagrid to show this info, and in my Datagrid.Columns I have a DataGridTemplateColumn
, inside a DataGridTemplateColumn.HeaderTemplate
and then a DataGridTemplateColumn.CellTemplate
Now inside my cell template for my 1st header, I want to show the index or element number of each element of my collection, the cell template is like this:
<DataGridTemplateColumn.CellTemplate>
<ItemContainerTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path= DataContext.CurrentPosition}"></TextBlock>
</ItemContainerTemplate>
</DataGridTemplateColumn.CellTemplate>
Now my DataContext.CurrentPosition
returns empty, I dont know if this is the correct property of the object to return the index.