Вы можете просто использовать это расширение
ме-
public static DataGridRow GetSelectedRow(this DataGrid grid)
{
return (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);
}
, и вы можете получить ячейку в DataGrid с помощью существующей строки и столбца ID:
public static DataGridCell GetCell(this DataGrid grid, DataGridRow row, int column)
{
if (row != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);
if (presenter == null)
{
grid.ScrollIntoView(row, grid.Columns[column]);
presenter = GetVisualChild<DataGridCellsPresenter>(row);
}
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
return cell;
}
return null;
}
grid.ScrollIntoView
является ключом, чтобы сделать эту работу в случае, если DataGrid виртуализируется и требуется ячейка не с точки зрения в настоящее время.
Проверить эту ссылку для деталей - Get WPF DataGrid row and cell
Здравствуйте, я внедрил метод, к которому вы можете получить доступ ко всем свойствам ячейки. –