我将一个对象(ScatterViewItem)与s:SurfaceDragDrop事件一起删除到SurfaceListBox上,当检测到整个SurfaceListBox上的删除时,它工作得很好,但是,我想知道在哪个SurfaceListBoxItem中删除了该对象。
我也想这样做,但对于一个ScatterView,即,检测该对象的ScatterViewItem被拖放到了哪个ScatterView上。
我的代码是这样的:
<s:SurfaceListBox
x:Name="listBoxList"
Background="{x:Null}"
AllowDrop="True"
s:SurfaceDragDrop.Drop="ListBox_Drop" >
</s:SurfaceListBox>
<s:ScatterView
x:Name="scatterList"
Background="{x:Null}"
AllowDrop="True"
s:SurfaceDragDrop.Drop="Scatter_Drop" >
</s:ScatterView>然后我把我的物品加起来:
listBoxList.Items.Add("ListBox Item 1");
listBoxList.Items.Add("ListBox Item 1");
listBoxList.Items.Add("ListBox Item 1");
scatterList.Items.Add("ScatterViewItem A");
scatterList.Items.Add("ScatterViewItem B");
scatterList.Items.Add("ScatterViewItem C");那么我怎样才能在ListBox_Drop和Scatter_Drop上得到这个项目呢?
编辑
通过罗伯特的回答,我设法解决了我的问题。因此,生成的代码如下所示(对于ScatterView):
<s:ScatterView
x:Name="scatterList"
Background="{x:Null}">
<s:ScatterView.ItemContainerStyle>
<Style TargetType="s:ScatterViewItem">
<EventSetter Event="s:SurfaceDragDrop.Drop" Handler="Scatter_Drop"/>
<Setter Property="AllowDrop" Value="True" />
</Style>
</s:ScatterView.ItemContainerStyle>
</s:ScatterView>对于SurfaceListBox来说
<s:SurfaceListBox
x:Name="listBoxList"
Background="{x:Null}">
<s:SurfaceListBox.ItemContainerStyle>
<Style TargetType="s:SurfaceListBox">
<EventSetter Event="s:SurfaceDragDrop.Drop" Handler="ListBox_Drop"/>
<Setter Property="AllowDrop" Value="True" />
</Style>
</s:SurfaceListBox.ItemContainerStyle>
</s:SurfaceListBox>发布于 2012-12-28 15:00:57
您需要设置AllowDrop并为每个单独的ScatterViewItem & ListBoxItem连接您的Drop事件处理程序。然后,事件的来源将是被丢弃的项目。
发布于 2013-05-11 10:05:38
我认为这是对上述解决方案的一个小小的修正。
<Style TargetType="s:SurfaceListBoxItem">作为反对
<Style TargetType="s:SurfaceListBox">https://stackoverflow.com/questions/14071389
复制相似问题