我有两个ListBox(在Silverlight 3应用程序中),每个ListBox都包含一个ListBoxDragDropTarget。 现在我用一些自定义对象(Person)填充SourceBox。 然后,我连接目标DragDtopTarget的DragOver事件。 这一切工作正常,我可以拖动&从第一个列表中删除元素到第二个。如何获取Silverlight应用程序中的拖动元素
现在我的问题:我怎样才能得到的元素,这是被拖动,以允许/不赞拖动? (我无法从FragEventArgs中获取Person)。
这是我的XAML:
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<controlsToolkit:ListBoxDragDropTarget
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
x:Name="DragSource">
<ListBox x:Name="lbSource" DisplayMemberPath="Name" />
</controlsToolkit:ListBoxDragDropTarget>
<controlsToolkit:ListBoxDragDropTarget
Grid.Column="1"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
x:Name="DragDest"
msWindows:DragDrop.AllowDrop="true">
<ListBox x:Name="lbDest" DisplayMemberPath="Name" />
</controlsToolkit:ListBoxDragDropTarget>
,这是我的dragover处理程序的代码:
Private Sub DragDest_DragOver(ByVal sender As Object, _
ByVal e As Microsoft.Windows.DragEventArgs) _
Handles DragDest.DragOver
Dim Pers = e.Data.GetData(GetType(Person))
End Sub
感谢您的任何提示如何解决这个问题。
克里斯托夫
编辑:
这是我的应答:-)的短版:
Private Sub DragDest_DragOver(ByVal sender As Object, _
ByVal e As Microsoft.Windows.DragEventArgs) _
Handles DragDest.DragOver
Dim Args As ItemDragEventArgs = e.Data.GetData(e.Data.GetFormats()(0))
Dim Sel As SelectionCollection = Args.Data
Dim Persons = (From Pe In Sel Select DirectCast(Pe.Item, Person)).ToList
End Sub