public void Color()
{
  DataGridRow row1 = (DataGridRow)this.dgSource.ItemContainerGenerator.ContainerFromIndex(i);
if (row1 != null)
row1.Background = new SolidColorBrush(Colors.Red);
}

这里有个坑,初始化时不能变色,必须等datagrid完成渲染后才能进行这种行变色。

因而先把form show 出来之后才执行变色方法。这个方法因为莫名其妙的BUG会导致变色不是我们想要的效果!!

CompareForm cf = new CompareForm();
cf.Show();
cf.Color();

第二种方法。用datagrid 的 Dg_LoadingRow方法

 private void Dg_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGridRow row = e.Row;
OrgTypeAuthResponseModel dataRow = e.Row.Item as OrgTypeAuthResponseModel;
if (dataRow == null)
return;
if (dataRow.Level == )//新字段紫色
{
if (row != null)
row.Background = new SolidColorBrush(Colors.LightBlue);
}
else if (dataRow.Level == )
{
if (row != null)
row.Background = new SolidColorBrush(Colors.LightCyan);
}
else
{
if (row != null)
row.Background = new SolidColorBrush(Colors.White);
}
}

二、WPF datagrid 行变色的更多相关文章

  1. C# WPF DataGrid 隔行变色及内容居中对齐

    C# WPF DataGrid 隔行变色及内容居中对齐. dqzww NET学习0     先看效果: 前台XAML代码: <!--引入样式文件--> <Window.Resourc ...

  2. wpf datagrid 行双击事件

    Xaml: <DataGrid ItemsSource="{Binding SessionList}" Grid.Row="2" Grid.Column= ...

  3. wpf datagrid 隔行变色

    <DataGrid AlternationCount="2"> <DataGrid.RowStyle> <Style TargetType=" ...

  4. wpf listview 行变色

    <ListView x:Name="listView_Date" Grid.Row="3" BorderBrush="{x:Null}" ...

  5. WPF入门教程系列二十三——DataGrid示例(三)

    DataGrid的选择模式 默认情况下,DataGrid 的选择模式为“全行选择”,并且可以同时选择多行(如下图所示),我们可以通过SelectionMode 和SelectionUnit 属性来修改 ...

  6. WPF设置DataGrid行内容高度自适应 与 TextBox/TextBlock内容高度自适应

    WPF设置DataGrid行内容高度自适应  TextBox/TextBlock内容高度自适应  参考: DataGrid 控件中的调整大小选项: http://msdn.microsoft.com/ ...

  7. WPF DataGrid 绑定行双击行命令

    WPF DataGrid 绑定行双击行命令 <DataGrid ...> <DataGrid.InputBindings> <MouseBinding MouseActi ...

  8. 在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色

    原文:在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色 在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色 例如根据学生的年龄来修改,年龄 ...

  9. WPF DataGrid 双击行 获得绑定数据

    原文:WPF DataGrid 双击行 获得绑定数据 1)增加事件 2)增加对象获取 1)事件代码 Datagrid 增加事件 MouseDoubleClick="dataGrid_Mous ...

随机推荐

  1. IDEA里如何多种方式打jar包,然后上传到集群

    关于IDEA里如何多种方式打jar包,然后上传到集群的问题? 前期准备,就是在,IDEA里,maven来创建项目.这里不多赘述. 1)用maven项目来打包,我推荐这个. (强烈推荐,简单又快速) S ...

  2. 029-FastDFSClient工具栏模板

    模板一: package cn.e3mall.common.utils; import org.csource.common.NameValuePair; import org.csource.fas ...

  3. 对Table_locks_immediate值的理解

    Table_locks_immediate表示立即释放表锁数,Table_locks_waited表示需要等待的表锁数,如果Table_locks_immediate / Table_locks_wa ...

  4. ruby **option作为函数参数,map的key必须是符号

    # NEW UNNAMED KEYWORD ARGUMENTSdef new_way(**options)return options[:foo]end# => :new_waynew_way( ...

  5. finally是否始终执行

    The only times finally won't be called are: If you call System.exit() If the JVM crashes first If th ...

  6. Basic .do(Can be used as template)

    #Time: 2017-05-06  #By : YINBin@122275    quit -sim    cd D:/Documents/Work/UVM_PRJ/uvm-crc-test set ...

  7. yii2 页面加载警告框

    在视图页面代码如下 <?php use kartik\alert\Alert; echo Alert::widget([ 'type' => Alert::TYPE_INFO, 'titl ...

  8. 初识JSP,第一天

    1.什么JSP java Server Page java 服务端的页面,它和servlet 一样可以提供动态的html 响应. 不同的是 servlet 以 java 代码 为主 jsp 以html ...

  9. vscode下eslint代码规范

    直接上规范吧: // 将设置放入此文件中以覆盖默认设置 { "editor.fontSize": 17, "editor.tabSize": 2, " ...

  10. hdu 2199 Can you solve this equation? 二分

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...