wpf 获取DataGrid某一个单元格,设置此单元格ToolTip内容和背景颜色
public void GetCell()
{
for (int i = 0; i < this.datagrid1.Items.Count; i++)
{
DataRowView drv = datagrid1.Items[i] as DataRowView;
DataGridRow row = (DataGridRow)this.datagrid1.ItemContainerGenerator.ContainerFromIndex(i);
if (i == 1)//如果行号等于1
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(1);//获取列号为1
cell.Background = new SolidColorBrush(Colors.Red);
Tooltip tip=new Tooltip();
tip.context="1234";
cell.Tooltip=tip;
}
}
}
public static T GetVisualChild<T>(Visual parent) where T : Visual
{
T childContent = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
childContent = v as T;
if (childContent == null)
{
childContent = GetVisualChild<T>(v);
}
if (childContent != null)
{
break;
}
}
return childContent;
}
//防止在取datagrid的row时出现错误,在Window_Loaded事件里面调用
public void Loed()
{
if (!Window.GetWindow(dataGrid1).IsVisible)
{
Window.GetWindow(dataGrid1).Show();
}
dataGrid1.UpdateLayout();
}
wpf 获取DataGrid某一个单元格,设置此单元格ToolTip内容和背景颜色的更多相关文章
- POI按照源单元格设置目标单元格格式
原文:http://jjw198874.blog.163.com/blog/static/1889845522011102401854234/ POI按照源单元格设置目标单元格格式 poi按照一个源单 ...
- WPF 获取DataGrid 控件选中的单元格信息
获取 DataGrid 选中的单元格的信息DataGridCellInfo cell_Info = this.studentTable.SelectedCells[0]; studentTableIt ...
- wpf 获取datagrid中模板中控件
//获取name为datagrid中第三列第一行模板的控件 FrameworkElement item = dataGrid.Columns[].GetCellContent(dataGrid.Ite ...
- Windows 10设置桌面图标间距、窗口的背景颜色、选中文字的背景颜色
Windows 10取消了“高级外观设置”(或者叫“窗口颜色和外观”设置),想调整一些参数只能进注册表了. 修改后可能需要注销或重启才能生效. 按Win+R,然后输入regedit进入注册表编辑器. ...
- android中设置ListView的选中的Item的背景颜色
ListView中没有默认的选择颜色,只有选择Item后的焦点颜色,鼠标点击时Item有颜色,放开鼠标后颜色也就没有了,要实现放开鼠标后选择项的背景还是有颜色的. 1.配置main.xml <? ...
- wpf 中DataGrid 控件的样式设置及使用
本次要实现的效果为: 这个DataGrid需要绑定一个集合对象,所以要先定义一个Experience类,包含三个字段 /// <summary> /// 定义工作经历类 /// </ ...
- wpf 获取datagrid 模板列中的控件
目前采用的 方法 (网上提供的一款) public static DataGridRow GetRow(DataGrid datagrid, int columnIndex) { ...
- Yii2.0中form->field如何获取主表的一个字段并且设置为只读
<?= $form->field($model, 'last_login_time')->textInput(['readonly' => 'true']) ?>
- 02 uni-app框架学习:设置全局样式统一每个页面的背景颜色
1.设置全局样式可以在App.vue里面 2.在每个页面的根view 里添加一个class名叫page
随机推荐
- 一个简单的AJAX实例
创建一个简单的XMLHttpRequest,从一个TXT文件中返回数据. 来源于菜鸟教程 <!DOCTYPE html><html><head><meta c ...
- leetcode reverse bits python
Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...
- 【翻译习作】 Windows Workflow Foundation程序开发-第一章04
1.2.3 Windows Workflow运行时 从Windows Workflow的角度看,可以将工作流活动当成是交给一个工作流处理器去执行的一系列指令或操作码.在Windows Workflo ...
- Flex 播放视频
Flex提供视频控件(VideoDisplay Control)播放图像和声音. 视频控件只支持播放,暂停和停止功能.不提供倒退和前进功能.只支持播放FLV格式的影片. 1. 视频控件标签 对应的MX ...
- 2013款Mac Pro“神秘”主机详解
2013款Mac Pro"神秘"主机详解 自2013年12月下旬新款Mac Pro在美国发布以来,经过一个月的等待终于在国内已到货,笔者亲自测试了这个号称"神秘" ...
- Linux之通配符与转义字符
通配符: *:代表任意字符,可以为空字符 ?:代表一个字符,不可以为空字符 转义字符: \
- hdu2444
#include <stdio.h> #include <string.h> #define black 1 #define white -1 ]; ]; ][]; int n ...
- 必须会的SQL语句(二) 创建表、修改表结构、删除表
1.创建数据库表 --使用哪个数据库,如果不写这一句是默认的数据库,也可以用鼠标选当前数据库 use testDB --创建表 Create Table tablename ( ...
- nginx安装详解
一.环境: 1.Linux:centos6.4(32位) 2.Gcc的编译环境.使用make命令编辑. yum install gcc-c++ 3.PCRE PCRE(Perl Compatible ...
- 整合jQuery和Prototype遇到的问题.
由于项目要在旧的服务器上面运行,而旧的服务器底层用了Prototype,所以需要解决jQuery和Prototype冲突的问题. 一.$符号冲突问题 这个还是很好解决的. jQuery.noConfl ...