也谈Wpf DataGrid选择行失去焦点后保持高亮的问题
来源:互联网 发布:淘宝买家好评率查询网 编辑:程序博客网 时间:2024/05/17 02:59
当wpf中的datagrid失去焦点后,选中行的颜色会变得很淡,几乎看不见。网上有人给出了解决方案:
<DataGrid Name="grid1" HorizontalAlignment="Left" Height="120" Margin="75,86,0,0" VerticalAlignment="Top" Width="282"> <DataGrid.Columns> <DataGridTextColumn Header="编号" Binding="{Binding compan.ID}"></DataGridTextColumn> <DataGridTextColumn Header="公司" Binding="{Binding CompanyName}"></DataGridTextColumn> <DataGridTextColumn Header="固定资产" Binding="{Binding FixedAssets}" Width ="*"></DataGridTextColumn> </DataGrid.Columns> <DataGrid.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Yellow"/> </DataGrid.Resources> </DataGrid>
来源: http://www.cnblogs.com/TaiYangXiManYouZhe/p/4495986.html
但我的grid是动态创建的,如何在代码里添加呢?写法如下:
注意Resources用于接收本地属性(即XML中的整个Resources段),缺省是空的。
m_gridCtrl.Resources.Add(SystemColors.InactiveSelectionHighlightBrushKey, new SolidColorBrush(Color.FromArgb(0xff, 0x33, 0x99, 0xff)));m_gridCtrl.Resources.Add(SystemColors.InactiveSelectionHighlightTextBrushKey, new SolidColorBrush(System.Windows.Media.Colors.White));
这么写后还有问题,执行效果如下,可以发现grid的底部也变色了。
这不是我们需要的。因为需要只对grid行做处理,XML写法如下:
<DataGrid.Resources> <Style TargetType="DataGridRow"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="DarkGray"/> </Style.Resources> </Style>
</DataGrid.Resources>
来源: http://www.itkeyword.com/doc/1744825483479414248/datagrids-selected-row-color-when-inactive
代码直接创建如下:
m_gridCtrl.RowStyle = new Style();m_gridCtrl.RowStyle.Resources.Add(SystemColors.InactiveSelectionHighlightBrushKey, new SolidColorBrush(Color.FromArgb(0xff,0x33,0x99,0xff)));m_gridCtrl.RowStyle.Resources.Add(SystemColors.InactiveSelectionHighlightTextBrushKey, new SolidColorBrush(System.Windows.Media.Colors.White));
0 0
- 也谈Wpf DataGrid选择行失去焦点后保持高亮的问题
- cxGrid失去焦点后如何继续保持选中单元的高亮状态
- VC ListControl/TreeControl失去焦点后,所选择行仍然高亮显示
- 如何使得CTreeCtrl 失去焦点后,选中项的颜色仍然保持不变,怎么实现?高亮
- CListCtrl控件失去焦点时仍保持高亮
- CListCtrl控件失去焦点时仍保持高亮
- listview控件(在listview失去焦点的情况下仍然保持item高亮)
- C#如何在ListView失去焦点的情况下仍然保持Item高亮
- C#如何在ListView失去焦点的情况下仍然保持Item高亮
- Listview 保持选中的item高亮,即使listview失去焦点
- 下拉框选择后,失去焦点的JS实现
- Winform中Treeview控件失去焦点,将选择的节点设置为高亮显示
- 如何使得clist ctrl 失去焦点后,仍然高亮
- android 解决EditText无法失去焦点和失去焦点后隐藏软键盘的问题
- select标签选择后失去焦点
- surfaceview 失去焦点后重新创建问题
- ListView失去焦点选中行不能高亮显示的问题解决
- C#ListView失去焦点选中行不能高亮显示的问题解决
- Java Lambda(4)
- 连接亚控OPC Server 遍历所有Tags
- madplay在AM335X上移植
- 面向对象的五大基本原则
- 安卓System.out.println控制台输出方法
- 也谈Wpf DataGrid选择行失去焦点后保持高亮的问题
- Map四种获取key和value值的方法,以及对map中的元素排序
- 微信小程序布局
- JSON.parse()和JSON.stringify()
- linux 下tomcat 项目汉字乱码
- JSP_5th_动作指令jsp:include
- [SMOJ1812]解方程
- Maven生命周期
- Predator:比Kinect更强的视频追踪算法