gpt4 book ai didi

c# - 当对象放在 SurfaceListBox 和 ScatterView 上时获取 SurfaceListBoxItem 和 ScatterViewItem

转载 作者:行者123 更新时间:2023-11-30 17:07:58 25 4
gpt4 key购买 nike

我正在使用 s:SurfaceDragDrop 事件将一个对象 (ScatterViewItem) 放到 SurfaceListBox 上,并且在检测到在整个 SurfaceListBox 上放置,但是,我想知道在哪个 SurfaceListBoxItem 中放置了对象。

除了 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 上的项目?

编辑

通过罗伯特的回答,我设法解决了我的问题。所以生成的代码将是这样的(对于 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>

最佳答案

您需要设置 AllowDrop 并为每个单独的 ScatterViewItemListBoxItem 连接您的 Drop 事件处理程序。然后事件的来源将是被丢弃的项目。

关于c# - 当对象放在 SurfaceListBox 和 ScatterView 上时获取 SurfaceListBoxItem 和 ScatterViewItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14071389/

25 4 0