Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm still messing around with this exact same issue too. I'm using a slightly modified version of Bea's Drag and Drop found <a href="http://hinshlabs.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31504" rel="nofollow noreferrer">here</a>, which is in VB instead of C#. When I used ScrollIntoView as described above, I could scroll down but not up. So I messed around and came up with this as my DropTarget_PreviewDragOver:</p> <pre><code> Private Sub DropTarget_PreviewDragOver(ByVal sender As Object, ByVal e As DragEventArgs) Dim draggedItem As Object = e.Data.GetData(Me.m_format.Name) Me.DecideDropTarget(e) If (Not draggedItem Is Nothing) Then If (TypeOf m_targetItemsControl Is ListBox) Then Dim lb As ListBox = CType(m_targetItemsControl, ListBox) Dim temp As Integer = m_insertionIndex Dim scroll As ScrollViewer = Utilities.GetScrollViewer(lb) If scroll.VerticalOffset = temp Then temp -= 1 End If If temp &gt;= 0 And temp &lt;= (lb.Items.Count - 1) Then lb.ScrollIntoView(lb.Items(temp)) End If End If Me.ShowDraggedAdorner(e.GetPosition(Me.m_topWindow)) Me.UpdateInsertionAdornerPosition() End If e.Handled = True End Sub </code></pre> <p>and I had to include this utility function, taken from <a href="http://www.developingfor.net/wpf/fun-with-the-wpf-scrollviewer.html" rel="nofollow noreferrer">here</a></p> <pre><code> Public Shared Function GetScrollViewer(ByVal listBox As ListBox) Dim scroll_border As Decorator = CType(VisualTreeHelper.GetChild(listBox, 0), Decorator) If (TypeOf scroll_border Is Decorator) Then Dim scroll As ScrollViewer = CType(scroll_border.Child, ScrollViewer) If (TypeOf scroll Is ScrollViewer) Then Return scroll Else Return Nothing End If Else Return Nothing End If End Function </code></pre> <p>which is great and all. Then running out what theuberk mentioned above with the adorner moving, and in the spirit of making this easy for someone else later, I added a variable to the DragDropAdorner class:</p> <pre><code> Private m_mouseDelta As Point </code></pre> <p>Added this to the last line of DragSource_PreviewMouseLeftButtonDown:</p> <pre><code> Me.m_mouseDelta = e.GetPosition(m_sourceItemContainer) </code></pre> <p>And turned ShowDraggedAdorner into:</p> <pre><code> Private Sub ShowDraggedAdorner(ByVal currentPosition As Point) If (Me.m_draggedAdorner Is Nothing) Then Dim adornerLayer As AdornerLayer = adornerLayer.GetAdornerLayer(Me.m_topWindow.Content) Me.m_draggedAdorner = New DraggedAdorner(Me.m_draggedData, DragDropBehavior.GetDragTemplate(Me.m_sourceItemsControl), m_topWindow.Content, adornerLayer) End If Me.m_draggedAdorner.SetPosition((currentPosition.X - m_mouseDelta.X), (currentPosition.Y - m_mouseDelta.Y)) End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload