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. ServiceLoader解读

    SPI的全名为Service Provider Interface.普通开发人员可能不熟悉,因为这个是针对厂商或者插件的.在java.util.ServiceLoader的文档里有比较详细的介绍. 简 ...

  2. 使用Microsoft Azure云平台中的Service Bus 中继 Intanet环境下的WCF服务。

    之前写的一篇文章:) 看起来好亲切. http://www.cnblogs.com/developersupport/archive/2013/05/23/WCF-ON-IIS-Azure-Servi ...

  3. 《高质量c++/c编程指南》学习摘要

    1. 尽可能在定义变量的同时初始化该变量(就近原则)——防止忘记初始化,引用未被初始化的变量,可能导致程序错误 2. 代码行最大长度宜控制在70~80个字符以内(长行拆分)——否则眼睛看不过来,也不便 ...

  4. webpack 报错 No PostCSS Config found 解决方案。

    webpack 报错 No PostCSS Config found  这个问题我在百度上找了好久,也没有找到解决方案,最后没有办法只能自己去啃官方文档,本案例在本人的webpack 学习感悟中已经写 ...

  5. 注册表修改 Devenv 默认启动 Visual Studio 版本

    本人机器上安装了多个版本Visual Studio.目前开发主要使用VS2015,,但每次使用运行->devenv 启动的都是 VS2013.所以不是很方便. 如果VS2013扩展包出问题要使用 ...

  6. spring boot2.0

    1. Spring boot 简介 1.1 spring boot的三大特性 组件自动装配:Web mvc, Web Flux,JDBC等 激活:@EnableAutoConfiguration 配置 ...

  7. java类加载机制及方法调用

    类加载机制 概述 类从被加载到虚拟机内存中开始,到卸载出内存为止,它的整个生命周期包括:加载(Loading).验证(Verification).准备(Preparation).解析(Resoluti ...

  8. 工作经验:mybatis 处理 oracle Long 类型

    前言:mybatis 接收 oracle 中 LONG 类型的,报错:无效的列类型: getCLOB not implemented for class oracle.jdbc.driver.T4CL ...

  9. SqlServer之一些小问题

    如何用变量代替字段名? 将语句赋给一个varchar 变量,下列语句等价于(假设传进去的@id=’name‘):'select  name from 表名' 如果直接执行这个语句,是没用的.@id不会 ...

  10. ARP原理和欺骗

    ARP--在TCP/IP协议栈中,最不安全的协议莫过于ARP了,我们经常听到的网络扫描,内网***,流量欺骗等等,他们基本上都与ARP有关系,甚至可以说,他们的底层都是基于ARP实现的.但是ARP的是 ...