主なアイデアは、何らかの形での値よりも大きいオフセット移動するときDoDragDrop関数はPreviewMouseMove()イベント、でmathodコールです。
1)ここでは、リストボックス:
<ListBox AllowDrop="True" Drop=" ListBox_Drop" PreviewMouseLeftButtonDown="ListBox_PreviewMouseLeftButtonDown" PreviewMouseMove="ListBox_PreviewMouseMove">
ListBoxItemsたちはDragAndDropを実装した場合に展開することはできませんエキスパンダ、あります。
2)今、私たちは(私はVB.NETを使用)2つの変数を追加する必要があります。
Private Sub ListBox_PreviewMouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
dragStartPoint = e.GetPosition(Me)
End Sub
4)PreviewMouseMoveに乗る:
Private isDragging As Boolean = False 'flag: is drag operation in process?'
Private dragStartPoint As Point 'coords of dragging start.'
3)は、プレビューマウスクリックでポイントCOORDSを開始覚えておいてください開始点を現在の移動点オフセットに移動する。 offsetがある値より大きい場合、DragAndDrop操作を開始し、フラグisDraggingを設定してこれを思い出します。
Private Sub ListBox_PreviewMouseMove(sender As System.Object, e As MouseEventArgs)
If e.LeftButton = MouseButtonState.Pressed Then
Dim diff As Vector = Point.Subtract(dragStartPoint, e.GetPosition(Me))
If (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance) OrElse (Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) Then
If Not isDragging Then
isDragging = True 'the flag is active until drop event raises.'
Dim lstBox As ListBox = TryCast(sender, ListBox) 'get sender ListBox'
If lstBox IsNot Nothing Then
Dim data As Object = GetDataFromListBox(lstBox, e.GetPosition(lstBox)) 'get data for drag-and-drop; need to be realized; there are some realizations at Stackoverflow.com presented.'
Dim effects As DragDropEffects = DragDrop.DoDragDrop(lstBox, data, DragDropEffects.Move) 'initiate drag-and-drop.'
End If
End If
End If
End If
End Sub
5)ドロップ操作をProccessing:
Private Sub ListBox_Drop(sender As Object, e As DragEventArgs)
isDragging = False 'reset isDragging flag.'
Dim lstBox As ListBox = TryCast(sender, ListBox) 'get sender ListBox.'
If lstBox IsNot Nothing Then
Dim myObj As MyClass = TryCast(e.Data.GetData(GetType(MyClass)), MyClass)
'...some actions'
End If
End Sub
私はこのアイデアを実現してきましたし、まさに私が必要だった作品だ:パンダとMouseLeftButtonClick ListBoxItems上
- は膨張して 崩壊しています、
- on MouseMoveドラッグした左ボタンDragAndDrop操作は です。 ListBoxItemsはソートすることができます。
XAMLのビットモードを投稿できますか?これは解決策を考えるには不十分だと私は思う。 –