二、WPF datagrid 行变色
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 行变色的更多相关文章
- C# WPF DataGrid 隔行变色及内容居中对齐
C# WPF DataGrid 隔行变色及内容居中对齐. dqzww NET学习0 先看效果: 前台XAML代码: <!--引入样式文件--> <Window.Resourc ...
- wpf datagrid 行双击事件
Xaml: <DataGrid ItemsSource="{Binding SessionList}" Grid.Row="2" Grid.Column= ...
- wpf datagrid 隔行变色
<DataGrid AlternationCount="2"> <DataGrid.RowStyle> <Style TargetType=" ...
- wpf listview 行变色
<ListView x:Name="listView_Date" Grid.Row="3" BorderBrush="{x:Null}" ...
- WPF入门教程系列二十三——DataGrid示例(三)
DataGrid的选择模式 默认情况下,DataGrid 的选择模式为“全行选择”,并且可以同时选择多行(如下图所示),我们可以通过SelectionMode 和SelectionUnit 属性来修改 ...
- WPF设置DataGrid行内容高度自适应 与 TextBox/TextBlock内容高度自适应
WPF设置DataGrid行内容高度自适应 TextBox/TextBlock内容高度自适应 参考: DataGrid 控件中的调整大小选项: http://msdn.microsoft.com/ ...
- WPF DataGrid 绑定行双击行命令
WPF DataGrid 绑定行双击行命令 <DataGrid ...> <DataGrid.InputBindings> <MouseBinding MouseActi ...
- 在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色
原文:在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色 在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色 例如根据学生的年龄来修改,年龄 ...
- WPF DataGrid 双击行 获得绑定数据
原文:WPF DataGrid 双击行 获得绑定数据 1)增加事件 2)增加对象获取 1)事件代码 Datagrid 增加事件 MouseDoubleClick="dataGrid_Mous ...
随机推荐
- javascript005_Object
•我们目前为止大多数引用类型都是Object类型的实例,Object也是ECMAScript中使用最多的一种类型(就像java.lang.Object一样,Object类型是所有它的实例的基础). – ...
- 创建自己的加密货币MNC——以太坊代币(二)
创建一个基于以太坊平台的分红币MNC,根据持有的代币数量,进行分红的算法.github地址: https://github.com/lxr1907/MNC 1.使用以太坊根据比例换购token MNC ...
- 【数组】Unique Paths
题目: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...
- WebDriver中的Actions对象
我们可以利用Actions对象来模拟鼠标的操作以及页面的拖拽 1.模拟鼠标的双击操作: 1)模拟双击一个div,验证点击之前的字体为14号 2)点击后字体为20号 Actions builder = ...
- python-Lock进程同步解决互斥
#!/usr/bin/python from multiprocessing import Process,Lock import time,sys def A(lock): with lock: f ...
- 深入理解java集合框架之---------Linked集合 -----构造函数
linked构造函数 1.LinkedList(): 构造一个空列表的集合 /** * 序列化 */ private static final long serialVersionUID = 1090 ...
- 微电子中的die-to-die和within-die
工艺制造中lot指按某种方式生成的硅柱状体,将这些lot切成薄片就称为wafer,wafer是进行集成电路制造的基板,一般以直径来区分,8寸.10寸,12寸等,或者以毫米来区分.直径越大材料的利用率越 ...
- python实例:快速找出多个字典中的公共键
1.生成随机字典 # 从abcdefg 中随机取出 3-6个,作为key, 1-4 的随机数作为 value s1 = {x : randint(1, 4) for x in sample('abcd ...
- IntelliJ使用指南—— 导入Eclipse的Web项目
通常一个团队中可能有人用eclipse,有人用intelliJ,那么经常会出现需要导入别人用eclipse建好的web项目.而IntelliJ提供了多种项目类型的导入方式,其中就有eclipse. 在 ...
- Visual studio 2017 c++ wcout 无法输出中文
wcout.imbue(locale(locale(), "", LC_CTYPE));