獲取當前所在行數
//獲取當前所在行數
int rowIndexE = 0;
var _cells = MyDataGrid.SelectedCells;
if (_cells.Any())
{
rowIndexE = MyDataGrid.Items.IndexOf(_cells.First().Item);
}
根據指定值行給grid設置背景色
if (vmodel.BatchNoDetail.batchNo != null && vmodel.BatchNoDetailList.Count > 0)
{
for (int i = 0; i < MyGrid.Items.Count; i++)
{
if (vmodel.BatchNoDetail.batchNo.Equals(vmodel.BatchNoDetailList[i].batchNo))
{
// vmodel.BatchNoDetailList[i].RowByBatchNoForeGround = "Red";
DataGridRow row = (DataGridRow)this.MyGrid.ItemContainerGenerator.ContainerFromIndex(i);
if (row != null) {
row.Background = Brushes.Red;
}
}
}
}