【问题标题】:Drag and Drop ListboxItems in WPF在 WPF 中拖放 ListboxItems
【发布时间】:2012-07-29 04:07:18
【问题描述】:

我试图弄清楚如何通过鼠标拖动来上下移动带有 MediaElements 的预填充列表框中的项目。我将不胜感激任何帮助。谢谢

【问题讨论】:

标签: wpf drag-and-drop listboxitems


【解决方案1】:

使用这个 dll:

 xmlns:ex="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"

然后您可以使用交互触发器并在视图模型中调用您的方法。

   <i:Interaction.Triggers>
       <i:EventTrigger EventName="Drop">
          <ex:CallMethodAction TargetObject="{Binding }" MethodName="DocumentListBox_Drop" />
       </i:EventTrigger>
   </i:Interaction.Triggers>

然后在视图模型中:

 Public Sub DocumentListBox_Drop(sender As Object, e As DragEventArgs)         
        Dim droppedFilePaths As String() = TryCast(e.Data.GetData(DataFormats.FileDrop, True), String())
        If Not droppedFilePaths Is Nothing Then
            For Each filepath As String In droppedFilePaths

            Next
        End If
End Sub

您的参考列表中应该已经有这个 dll,如果没有,您可能需要在 google 上查找它。另请注意:除了我刚刚向您展示的内容之外,还有更多内容,例如确保将 allowdrop 设置为 true 等等。

【讨论】:

    猜你喜欢
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-09
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多