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内容和背景颜色的更多相关文章

  1. POI按照源单元格设置目标单元格格式

    原文:http://jjw198874.blog.163.com/blog/static/1889845522011102401854234/ POI按照源单元格设置目标单元格格式 poi按照一个源单 ...

  2. WPF 获取DataGrid 控件选中的单元格信息

    获取 DataGrid 选中的单元格的信息DataGridCellInfo cell_Info = this.studentTable.SelectedCells[0]; studentTableIt ...

  3. wpf 获取datagrid中模板中控件

    //获取name为datagrid中第三列第一行模板的控件 FrameworkElement item = dataGrid.Columns[].GetCellContent(dataGrid.Ite ...

  4. Windows 10设置桌面图标间距、窗口的背景颜色、选中文字的背景颜色

    Windows 10取消了“高级外观设置”(或者叫“窗口颜色和外观”设置),想调整一些参数只能进注册表了. 修改后可能需要注销或重启才能生效. 按Win+R,然后输入regedit进入注册表编辑器. ...

  5. android中设置ListView的选中的Item的背景颜色

    ListView中没有默认的选择颜色,只有选择Item后的焦点颜色,鼠标点击时Item有颜色,放开鼠标后颜色也就没有了,要实现放开鼠标后选择项的背景还是有颜色的. 1.配置main.xml <? ...

  6. wpf 中DataGrid 控件的样式设置及使用

    本次要实现的效果为: 这个DataGrid需要绑定一个集合对象,所以要先定义一个Experience类,包含三个字段 /// <summary> /// 定义工作经历类 /// </ ...

  7. wpf 获取datagrid 模板列中的控件

    目前采用的 方法  (网上提供的一款) public static DataGridRow GetRow(DataGrid datagrid, int columnIndex)        {    ...

  8. Yii2.0中form->field如何获取主表的一个字段并且设置为只读

    <?= $form->field($model, 'last_login_time')->textInput(['readonly' => 'true']) ?>

  9. 02 uni-app框架学习:设置全局样式统一每个页面的背景颜色

    1.设置全局样式可以在App.vue里面 2.在每个页面的根view 里添加一个class名叫page

随机推荐

  1. MySQL学习笔记(二)

    二.SQL基本知识 SQL 是一种典型的非过程化程序设计语言,这种语言的特点是:只指定哪些数据被操纵,至于对这些数据要执行哪些操作,以及这些操作是如何执行的,则未被指定.非过程化程序设计语言的优点在于 ...

  2. 09_platform-tools简介&常见adb指令

    SDK下面的文件夹说明add-ons 附加的附属的一些信息.docs Android开发的帮助文件.extras 支持的jar包,高版本兼容底版本.google usb的驱动.platforms 存放 ...

  3. java中HashMap的用法

    重点介绍HashMap.首先介绍一下什么是Map.在数组中我们是通过数组下标来对其内容索引的,而在Map中我们通过对象来对对象进行索引,用来索引的对象叫做key,其对应的对象叫做value.在下文中会 ...

  4. uitableviewcell高度自适应笔记

    今天看了几篇uitableviewcell高度自适应的文章,大体分为两种方式. 第一种方式,cell里面有label,在cellforrow绘制的时候计算Label的可能高度,并且在此时重新计算cel ...

  5. 详解YUV与RGB数据格式-2016.01.20

    参考文献 什么是I帧,P帧,B帧 图文详解YUV420数据格式 RGB565 与 RGB888的相互转换 最简单的基于FFmpeg的libswscale的示例(YUV转RGB)

  6. WWF3事务和异常处理类型活动<第四篇>

    一.FaultHandler 添加一个工作流图如下: 首先添加一个Seruence,在里面添加3个Code,外面添加一个Code,打开Seruence错误处理,在容器里添加一个faultHandler ...

  7. hdu1505

    the main algorithm as the 1506 #include <stdio.h> #include <iostream> #include <strin ...

  8. 004远程登录Linux系统

    通过windows主机远程登录Linux主机 前提一:从windows能ping通Linux 前提二:关闭Linux防火墙,运行命令:/etc/init.d/iptables stop (1)使用Pu ...

  9. 如何获取tableview中当前选中的cell

    当我们点击某个cell时,会执行下面这个方法,方法中调用另一方法执行具体操作: - (void)tableView:(UITableView *)tableView didSelectRowAtInd ...

  10. 自定义Attribute 服务端校验 客户端校验

    MVC 自定义Attribute 服务端校验 客户端校验/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) *//* Autho ...