/// <summary> /// Converts an <see cref="DataGridCell"/> to its row index. /// </summary> /// <param name="value">Value to be converted.</param> /// <param name="targetType">Type to convert to.</param> /// <param name="parameter">Optional conversion parameter.</param> /// <param name="culture">Globalization info.</param> /// <returns>The index of the cell. If none found, will return -1.</returns> public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) { DataGridCell item = value as DataGridCell; DataGridRow dataGridRow = item?.Ancestors().OfType <DataGridRow>().FirstOrDefault(); DataGrid dataGrid = dataGridRow?.Ancestors().OfType <DataGrid>().FirstOrDefault(); Int32 index = dataGrid?.ItemContainerGenerator.IndexFromContainer(dataGridRow) ?? -1; return(index.ToString()); }