以前我尝试将对象从 a 拖放LibraryContainer
到 a 上ScatterView
,反之亦然,这很简单,默认情况下LibraryContainer
,LibraryStack
和LibraryBar
支持拖放事件。结合DragDropScatterView.cs
Surface 2.0 SDK 提供的 ShoppingCart 示例非常简单。
现在我希望能够将 a 拖放UserControl
到ScatterView
4 上,反之亦然,即像这样:http: //goo.gl/zZIdg。
根据我的研究,有一种方法可以做到这一点,可以在这里找到:http: //msdn.microsoft.com/en-us/library/ff727736.aspx。但是,这里他们不使用DragDropScatterView.cs
,它以不同的方式完成。您有两个ObservableCollections
(一个源和一个目标), theScatterViewItems
和SurfaceListBox
.
在这个示例中我不喜欢的一件事是,ScatterViewItems
可以拖动的 并没有真正的缩放属性,因为当用户单击 时ScatterViewItem
,它会创建视觉样式并隐藏ScatterViewItem
并且当您放下它时,它会更新坐标和方向,ScatterViewItem
并使其可见。我决定不走这条路,因为我想要一个正常的ScatterViewItem
行为。
我想要做的基本事情是拥有,例如 a Label
,并且在 a 侧,ScatterView
并且能够拖动它Label
(创建一个视觉光标 - 已经完成)并将其放在 上ScatterView
,创建ScatterViewItem
具有相同属性的a原创Label
。我尝试使用 the 来执行此操作,DragDropScatterView.cs
但是当我使用Label
my droppingCursor.Data
(on the DragDropScatterView.cs
) isnull
时,我认为发生这种情况是因为draggedElement.DataContext
(on the LabelView.xaml.cs
) is also null
,但是null
当我使用SurfaceListBox
.
我在这里提供了一个代码示例:http: //sdrv.ms/VDuHq5。在SurfaceWindow1.xaml
里面有TagVisualization
和 的容器,在ScatterView
里面LabelView.xaml
调用了`TagVisualization
。
如果有人可以帮助我,我将不胜感激。