I have a DataGrid with DataGridTemplateColumns. In the TemplateColumn, I use a DataTrigger which works fine. It retrieves the Item Count from the DataGrid parent.
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
...
<!-- this works fine! -->
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type DataGrid}}, Path=Items.Count}" Value="1">
...
</DataTrigger>
</DataTemplate>
Is it possible, to retrieve the current RowIndex in which the template is placed ?
I think that it is possible to bind to the current DataGridRow. A Binding Path of “GetIndex()” won’t be supported, like:
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type DataGridRow}}, Path=GetIndex()}" Value="0"> <!-- error: GetIndex() -->
Is there an alternative, to bind to DataGridRow.GetIndex() from xaml ?
You can only bind to
Propertiesand not methods of an object. You need to use aIValueConverterin case you want to bind to method –and bind it like this –