ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

WPF Beginner - Drag&Drop Item in listview

2019-08-11 23:06:48  阅读:265  来源: 互联网

标签:use Beginner true Drop Item itemToDrag listView com GetPosition


原文链接:http://www.cnblogs.com/pangpangxiong/archive/2009/08/26/1554400.html How to drag&Drop listview items?

The first thing come to my mind is that, to use evensetter. However, it is not true. The Drag & Drop event is never triggered.

Then I searched and found a log of articles. The famous one is: http://www.codeproject.com/KB/WPF/ListViewDragDropManager.aspx.
It is using PreviewMouseButtonDown, PreviewMouseMove, PreviewMouseLeftButtonUp, to track the mouse activities. And some tricks are also used, for example, interropt system32 API, defining thread hold of "Drag".

1. It is using PreviewMouseButtonDown, PreviewMouseMove, PreviewMouseLeftButton down. to track the mouse activities. why use preview events not bubble events? 
Check MSDN, and my previous log, it is said clearly: A lot of control has suppressed MouseLeftButtonDown. If you still want to capture this event, use previewlmosuebutton down.

2. I modified the interupt API, use MouseEvent.GetPosition() instead.

3. The Adorner thing, i am using MSDN sample, http://blogs.msdn.com/marcelolr/archive/2006/03/03/showing-drag-drop-feedback-on-the-wpf-adorner-layer.aspx instead. it is much clearly.

Follownig are some code snippets, a lot of bugs...

 
void ListView_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)

{

     if (_isDown)

    {

         DragFinished(e.GetPosition(listView));

         e.Handled = true;

    }

}

 

void ListView_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)

{

    if (_isDown)

   {

        if ((_isDragging == false) &&

            ((Math.Abs(e.GetPosition(listView).X - _startPoint.X) > SystemParameters.MinimumHorizontalDragDistance)

           || (Math.Abs(e.GetPosition(listView).Y - _startPoint.Y) > SystemParameters.MinimumVerticalDragDistance)))

     {

           DragStarted();

     }

     if (_isDragging)

   {

          DragMoved();

    }

  }

}

 

void ListView_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)

{

   _currentDragItem = IndexUnderDragCursor;

if (_currentDragItem < 0)

return;

ListViewItem itemToDrag = this.GetListViewItem(_currentDragItem);

if (itemToDrag == null)

return;

_isDown = true;

_startPoint = e.GetPosition(listView);

_originalElement = itemToDrag;

itemToDrag.CaptureMouse();

e.Handled = true;

}


 

转载于:https://www.cnblogs.com/pangpangxiong/archive/2009/08/26/1554400.html

标签:use,Beginner,true,Drop,Item,itemToDrag,listView,com,GetPosition
来源: https://blog.csdn.net/weixin_30481087/article/details/99239682

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有