Search code examples
wpfinsertion

Insertion mark for ListView in WPF


I need create Insertion mark for my ListView during Drag&Drop system. (as Powerpoint). I'm found Insertion mark in Componentowl but I need create my own insertion mark for Drag&Drop in ListView.


Solution

  • Here's how it should be done in theory:

    Handle MouseLeftButtonDown, MouseMove and MouseLeftButtonUp events of the draggable element. When the mouse button is pressed, you need to capture mouse on the element in order to get MouseMove events while dragging and release the capture when button is released.

    In MouseMove eventhandler you need to find out elements under mouse and show the 'insertion mark' in a Popup control or in Adorner Layer (Popup control is used to show content in top of everything) and update its position.

    Alternativley, you may use DragEnter, DragOver and DragLeave eventhandlers on the drop target element to whow the insertion mark in popup or adorner layer.

    You may read this article: http://blogs.msdn.com/b/jaimer/archive/2007/07/12/drag-drop-in-wpf-explained-end-to-end.aspx

    or this article: https://cuteprogramming.wordpress.com/2010/12/19/drag-and-drop-reordering-in-wpf-listview/ which refers to this article: http://www.codeproject.com/KB/WPF/ListViewDragDropManager.aspx

    here is another solution: https://codeblitz.wordpress.com/2009/06/17/wpf-drag-drop-adorner/