关于C# wpf DataGrid单元格双击设置单元格内容

1、我是使用了 visual stadio 2015, 用的C# WPF写个工具,但是发现wpf原生没有涉及表格的东西(类似 winform·的DataGridView),所以使用的是toolkit工具类中的DataGrid,作为表表格展现。
2、本意是做个单元格实现双击则单元格的内容在“自动”和”“ 间切换,但是发现使用DataGrid的MouseDoubleClick事件时发现当鼠标双击整个DataGrid的任何地方都会触发双击事件,因此要判断当前双击的位置,顾查询了很多资料(TOOLkit的资料忒少了。msdn上关于DataGrid的无法区分是否适用于该DataGrid)。
3、这是我的源代码片段,其中this.dataGrid_YHDZ_YHDZD是我的DataGrid名字。
private void dataGrid_YHDZ_YHDZD_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
Point aP = e.GetPosition(this.dataGrid_YHDZ_YHDZD);
IInputElement obj = this.dataGrid_YHDZ_YHDZD.InputHitTest(aP);
DependencyObject target = obj as DependencyObject;

        while (target != null)
        {
            if (target is DataGridCell)
            {
                String value = ((target as DataGridCell).Content as TextBlock).Text;
                if (value == "") {
                    ((target as DataGridCell).Content as TextBlock).Text= "手动";
                }
                if (value == "手动") {


                    ((target as DataGridCell).Content as TextBlock).Text= "";
                }

                break;
            }


            target = VisualTreeHelper.GetParent(target);
        }
    }

4、这是原文连接:http://blog.csdn.net/zhantianyou/article/details/8951208感谢hantianyou

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值