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. C语言sizeof陷阱

    执行以下程序,查看输出: #include <stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int  ...

  2. docker学习笔记1 -- 安装和配置

    技术资料 docker中文官网:http://www.docker.org.cn/ 中文入门课程:http://www.docker.org.cn/book/docker.html docker学习笔 ...

  3. iOS copy&mutableCopy理解

    Copy&mutableCopy   通过copy方法可以创建可变或不可变对象的不可变副本,通过mutableCopy可以创建可变或不可变对象的可变副本. 拷贝分为浅拷贝和深拷贝: 浅拷贝:指 ...

  4. 金额input框控制只能小数点后有两位的有效数字

    <%@include file="/WEB-INF/jsp/common/common.jsp" %> <title>价格录入限定</title> ...

  5. DataGridview焦点不移开不保存数据问题

    this.datagridLeft.ClearSelection();                this.datagridLeft.Refresh();                this. ...

  6. 嵌入在C++程序中的extern "C"

    1.extern的作用 extern是C/C++语言中表明函数和全局变量作用范围(可见性)的关键字,可以告知编译器,用extern声明的函数和变量可以在本模块或其它模块中使用. 通常,在模块的头文件中 ...

  7. sessionStorage html5客户端本地存储之sessionStorage及storage事件

    可以看一下<JavaScript本地存储实践(html5的localStorage和ie的userData)>sessionStorage和上文中提到的localStorage非常相识,方 ...

  8. 005windows与Linux文件共享

    基于网络的文件共享: 前提一:从windows能够ping通Linux: 前提二:关闭Linux防火墙,命令[/etc/init.d/iptables stop]: 方法一:通过WinSCP 步骤一: ...

  9. mac 显示隐藏文件夹

    在终端输入   defaults write com.apple.finder AppleShowAllFiles -boolean true;killall Finder即可

  10. 高仿精仿开心网应用android源码

    今天早上看到了一个不错的安卓应用源码项目,真的非常不错高仿精仿开心网应用android源码下载,希望大家能够喜欢.       原文:http://android.662p.com/thread-29 ...