我在一個SurfaceListBox
掉落的物體(ScatterViewItem
)與s:SurfaceDragDrop
事件下降,檢測對整個SurfaceListBox
下落時,它工作正常,但是,我想知道哪個對象被刪除了哪個SurfaceListBoxItem
。獲取SurfaceListBoxItem和ScatterViewItem當物體在SurfaceListBox和ScatterView
我也想這樣做,但對於ScatterView
,即檢測該對象的哪個ScatterViewItem
被丟棄。
我的代碼是這樣的:
<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
項目嗎?
編輯
過Robert答案我設法解決我的問題。所以生成的代碼會是這樣的(爲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>
這工作,但它似乎沒有用正確的方法去做。如果我有50個項目,我應該有一個下降事件,而不是50個。如果我在這裏失去了一些東西,可以啓發我。 –
您可以將所有50個項目指向完全相同的事件處理函數,但每個項目都需要直接在其上設置AllowDrop –
感謝羅伯特提供的信息,我解決了這個問題,解決方案在我的第一篇文章中。 –