0
표시된 셀의 색을 변경하려면 DataGrid의 일부 셀을 표시하고 싶습니다. 나는 하나의 셀에 대해 그들과 코드를이 작업을 수행 할 수 있습니다표시된 셀의 색 변경
public static DataGridRow GetRow(this DataGrid dataGrid, int index)
{
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);
if (row == null)
{
dataGrid.UpdateLayout();
dataGrid.ScrollIntoView(dataGrid.Items[index]);
row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);
}
return row;
}
public static int GetRowIdx(this DataGrid dataGrid, DataGridCellInfo cellInfo)
{
// Use reflection to get DataGridCell.RowDataItem property value.
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(cellInfo.Item);
if (row == null)
throw new NullReferenceException("Fehler: Keine Index gefunden da DataGridRow null!");
return row.GetIndex();
}
public static DataGridCell GetCurrentCell(this DataGrid dataGrid)
{
int row = GetRowIdx(dataGrid, dataGrid.CurrentCell);
int column = dataGrid.CurrentColumn.DisplayIndex;
return GetCell(dataGrid, row, column);
}
호출 :
DataGridCell currentCell = DataGridExtension.GetCurrentCell(dataGrid1);
currentCell.Background = Brushes.LightGray;
사람이 코드를 변경하는 방법을 알고를, 내가 예를 들어 5 개 세포를 표시하고 자신의 색상을 변경할 수 있도록 ?
당신은 DataGridCell의 컬렉션을 만들고 버튼을 클릭하는 것과 같은, 다른 이벤트에 모두 표시 할 수