Silverlight从代码后面设置ListBoxDragDropTarget子项/项

时间:2014-01-02 11:48:51

标签: silverlight xaml

我有一个应用程序,它以编程方式从后面的代码构建列表框。 我想使列表框中包含的元素可拖动。

我知道这可以通过使用以下xaml代码使用ListBoxDragDropTarget在xaml中实现:

<toolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True">
    <ListBox Width="200" Height="500" x:Name="FromBox" DisplayMemberPath="FullName">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>
</toolkit:ListBoxDragDropTarget>

但是我需要从后面的代码而不是通过xaml实现这一点。有没有办法从后面的代码设置拖放目标?

我似乎无法找到一个允许设置dragDropTarget的属性。类似的东西:

 Dim target As New ListBoxDragDropTarget

 target.children.add(listbox) / target.items 

不确定是否可能。

提前致谢!

1 个答案:

答案 0 :(得分:0)

最后对问题进行了排序。

我最终将ListBoxDragDropTarget.content设置为列表框。 (其中包含多个对象)

  target.Content = listBox

然后我将目标添加到wrapPanel,最后将wrapPanel添加到我的主网格中。

 wp.Children.Add(target)
 grdApps.Children.Add(wp)

拖放功能现在正在运行!