开发者

How to detect when mouse on scroll in wpf

I have 2 listboxes and I drag items from one to the other. Problem is that when the scroll is visible on listbox and if I click on scroll to move up/down, it starts dragging again. Is there any way to detect when mouse is over the scroll area so I can prevent it from initiating the drag action?

Following is the code:

Private Sub lstbox_PreviewMouseLeftButtonDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) 'Handles lstFieldsAvailable.PreviewMouseLeftButtonDown
    _mouseDownPos = e.GetPosition(Nothing)
    _isMouseDown = True
    _mouseDownSource = sender
End Sub

Private Sub lstbox_PreviewMouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs) 'Handles lstFieldsAvailable.PreviewMouseMove
    Dim mousePos As Point = e.GetPosition(Nothing)
    Dim diff As Vector = _mouseDownPos - mousePos
    Dim lstbox As ListBox = CType(sender, ListBox)

    If _isMouseDown And e.LeftButton = MouseButtonState.Pressed And lstbox.SelectedItems.Count > 0 And _
        lstbox.IsMouseOver And _
        (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance Or _
         Math.Abs(diff.Y) > SystemParameters.MinimumVe开发者_如何转开发rticalDragDistance) Then

        'get the selected items
        Dim dragData As New DragDataStruct(lstbox)
        For Each item As String In lstbox.SelectedItems
            dragData.Items.Add(item)
        Next

        DragDrop.DoDragDrop(lstbox, dragData, DragDropEffects.Move)

    End If
End Sub


Do you really have to set the ListBox as the drag source ...

Cant you use ListBoxItem as the drag source? If you do that then ListBoxItem will automatically exclude the scrollbars from their draggable regions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜