zoukankan      html  css  js  c++  java
  • wpf datagrid row的命中测试

    1. 添加鼠标左键处理

    AddHandler(DataGrid.MouseLeftButtonDownEvent, new RoutedEventHandler(grdStudyList_MouseLeftButtonDown), true);

    2. 命中测试

     private void grdStudyList_MouseLeftButtonDown(object sender, RoutedEventArgs e)
            {
                Point CurrentPosition = System.Windows.Input.Mouse.GetPosition(grdStudyList);

                _hitResultsList.Clear();

                VisualTreeHelper.HitTest(grdStudyList, null,
                    new HitTestResultCallback(DataGridHitTestResult),
                    new PointHitTestParameters(CurrentPosition));

                if (0 >= _hitResultsList.Count)
                {
                    return;
                }

                var element = _hitResultsList.Where(y => y.GetType() == typeof(DataGridHeaderBorder)
                    || y.GetType() == typeof(ScrollViewer));

                bool isGridCell = true;
                foreach (var x in element)
                {
                    isGridCell = false;
                }

                if (!isGridCell)
                {
                    return;
                }
     
               //后续逻辑处理
            }


         //

    private List<DependencyObject> _hitResultsList = new List<DependencyObject>();

     public HitTestResultBehavior DataGridHitTestResult(HitTestResult result)
            {
                // Set the behavior to return visuals at all z-order levels.

                if (3 > _hitResultsList.Count)
                {
                    _hitResultsList.Add(result.VisualHit);

                    return HitTestResultBehavior.Continue;
                }
                else
                {
                    return HitTestResultBehavior.Stop;
                }
            }
    https://muzizongheng.blog.csdn.net/
  • 相关阅读:
    iOS面试题6.30总结
    关于外挂
    webstorm快捷方式
    HTML注释的一些规范
    认识Python
    正体复本术解决容易疲劳、不能持续集中精力工作-海淀区非物质文化遗产:#正体复本术#
    皮肤发痒的观察与思考
    win10不错的快捷键
    项目属性的target platform和target platform version到底是什么(vs2015开发windows驱动小记)
    玩Web虎-运行时受保护文件不可复制
  • 原文地址:https://www.cnblogs.com/muzizongheng/p/3167257.html
Copyright © 2011-2022 走看看