zoukankan      html  css  js  c++  java
  • 关于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

  • 相关阅读:
    Markdown 画 UML 图(六)
    Markdown 高级技巧(五)
    Markdown 链接、图片、表格(四)
    16.3Sum Closet
    15.Three Sum
    11.Container With Most Water
    1.Two Sum
    优化学习笔记5
    优化学习笔记4
    优化学习笔记3
  • 原文地址:https://www.cnblogs.com/sjqq/p/8454564.html
Copyright © 2011-2022 走看看