WPF DataGrid ListView 等等 改变 选中行 颜色;以及 不变的原因
WPF中改变选中行的颜色是很简单的,就是用触发器:比如:以DataGrid为例: DataGrid.RowStyle Style TargetType= DataGridRow SetterProperty= Background Value= White / Style .Triggers TriggerProperty= IsMouseOver Value= True SetterProperty= Background Value= LightGray / /Trigger TriggerPrope
WPF中改变选中行的颜色是很简单的,就是用触发器:比如:以DataGrid为例:
<DataGrid.RowStyle >
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightGray"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="LightGray"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
但是,我告诉你,如果你没有设置cellStyle,你将会发现上面的代码“貌似”不工作,没用。这一点对 ListView 等等相似控件都是一样的。
事实上,上面代码已经起作用了。IsSelected确实被触发了。问题在哪呢?
答案正确,就在CellStyle上。因为RowStyle 的背景改变了,但CellStyle没变,你是看不出来的。
也就是RowStyle很冤,因为CellStyle是在其上的。所以会被覆盖。原因就是“黑人”“白人”穿着“黑衣服”看起来都是黑的。
改变的方法如下:
加入CellStyle:
<DataGrid.CellStyle >
<Style TargetType="DataGridCell">
<Style.Triggers >
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
WPF DataGrid ListView 等等 改变 选中行 颜色;以及 不变的原因的更多相关文章
- Silverlight 查询DataGrid 中匹配项 ,后台改变选中行颜色
需求:根据关键字(参会人号码或名称)查找参会人,在datagird 中高亮显示 界面:我在界面上增加了一个文本框和按钮,进行查找操作 操作说明: 根据关键字进行搜索:输入关键字 点击查找,如果找到 以 ...
- 【WPF】通过修改dataGrid的cell的style,改变选中行失去焦点时的颜色
<Style TargetType="{x:Type DataGridCell}"> <Style.Triggers> <Trigger Proper ...
- listview改变选中行字体颜色
[android]listview改变选中行字体颜色 目标:选中item,其字体设置为#3197FF,未选中的,其字体为#FFFFFF 与listvew设置选中行item背景图片一样,使用select ...
- 【android】listview改变选中行背景图片
[android]listview改变选中行背景图片 目标:当item选中时,改变其背景图片.效果图如下: 直接在listview的xml文件中使用listselector: 1 2 3 4 5 6 ...
- WPF,通过修改dataGrid的cell的style,改变选中行失去焦点时的颜色 4.0可用
<Style TargetType="{x:Type DataGridCell}"> <Style.Triggers> <Trigger Proper ...
- WPF中ListView如何改变选中条背景颜色
先上图 解决方法: <ListView ...> <ListView.ItemContainerStyle> <Style TargetType="{x:Typ ...
- wpf DataGrid CheckBox列全选
最近在wpf项目中遇到当DataGrid的header中的checkbox选中,让该列的checkbox全选问题,为了不让程序员写自己的一堆事件,现写了一个自己的自定义控件 在DataGrid的 &l ...
- easyui datagrid 键盘上下控制选中行
扩展datagrid的一个方法keyCtr $.extend($.fn.datagrid.methods, { keyCtr : function (jq) { return jq.each(fun ...
- DOJO dataGrid 单击单元格选中行
onCellClick: lang.hitch(this, function(event){ //单元格单击事件 var grid = dijit.byId("__geodisa_grid& ...
随机推荐
- spring boot 下使用@ConponentScan注解遇到的问题
问题描述 如果你心急看结果,请直接到本文末尾 今天使用了注解操作spring boot,一开始程序无法启动,提示无法找到一个注解注入的类,查询网上,有人说使用@ConponetScan注解,可以指定需 ...
- Halcon图像采集助手提示找不到指定DLL文件
问题原因: Halcon软件更新导致某些图像采集DLL失效,这个时候就需要去MVTEC官网下载图像采集接口补丁程序,MVTEC官网地址http://www.mvtec.com/. 对于其他模块失效的D ...
- [leetcode-783-Minimum Distance Between BST Nodes]
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...
- codeforces 295C Greg and Friends(BFS+DP)
One day Greg and his friends were walking in the forest. Overall there were n people walking, includ ...
- 硬件电路中VCC,VDD,VEE,VSS有什么区别
电路中GND和GROUND.VCC,VDD,VEE,VSS有什么区别 一.解释 DCpower一般是指带实际电压的源,其他的都是标号(在有些仿真软件中默认的把标号和源相连的)VDD:电源电压(单极器件 ...
- Python字符串格式化表达式和格式化方法
Python格式化字符串由两种方式可以选择:一种是格式化表达式(Formatting Expression),一种是格式化方法(Formatting Method).其中格式化表达式在全Python版 ...
- 使用libpcab抓包&处理包
#include <stdio.h> #include <stdlib.h> #include <strings.h> #include <string.h& ...
- c#和.net区别
.net 包含两大部分:.net framework类库和公共语言运行库(CLR) .net framework类库,就是微软工程师写好的各种功能类,例如math类. 公共语言运行库:1.与操作系统进 ...
- bootstrap使用中遇到的坑
一.例如: <div class="form-group"> <label class="control-label col-lg-3"> ...
- iOS AVAudioPlayer播放音频时声音太小
iOS AVAudioPlayer播放音频时声音太小 //引入AVFoundation类库,设置播放模式就可以了 do { try AVAudioSession.sharedInstance().ov ...