2012-12-28 34 views
3

我在一個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_DropScatter_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> 

回答

1

您需要設置AllowDrop和掛鉤您的Drop事件處理程序爲每個ScatterViewItem & ListBoxItem。那麼事件的來源將是被拋棄的項目。

+0

這工作,但它似乎沒有用正確的方法去做。如果我有50個項目,我應該有一個下降事件,而不是50個。如果我在這裏失去了一些東西,可以啓發我。 –

+1

您可以將所有50個項目指向完全相同的事件處理函數,但每個項目都需要直接在其上設置AllowDrop –

+0

感謝羅伯特提供的信息,我解決了這個問題,解決方案在我的第一篇文章中。 –

1

我認爲上述解決方案的一個小小的更正。

<Style TargetType="s:SurfaceListBoxItem"> 

爲反對

<Style TargetType="s:SurfaceListBox"> 
+0

這應該是一條評論。 – Mateusz

+0

不知道如何評論... – PotatoJam