我有一个Datagrid
其中添加项目使用grid.Items.Insert(0, row);
我总是希望插入的最后一行先在网格上显示。 我也希望第一行与其他人有不同的颜色。为此我使用LoadingRow
事件:将第一行数据网格设置为不同的颜色
private void dataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
dataGrid.RowBackground = new SolidColorBrush(Colors.AntiqueWhite);//set all rows to default color
e.Row.Background = new SolidColorBrush(Colors.CornflowerBlue); //set current=>1st row row to BLue
}
但是添加的每一行是越来越有色CornflowerBlue
没有先前添加的行改为AntiqueWhite
。 我错过了明显的东西,真的很感激任何指导。
可能是这个链接将帮助你出现着色问题。 http://stackoverflow.com/questions/23753299/set-background-color-only-for-the-first-row-in-a-datagrid –