XAML 当CanReorderItems在UWP列表视图上设置为true时,为什么我无法获得DragItemsCompleted和DragItemsStarting事件?

0lvr5msh  于 2022-12-07  发布在  Git
关注(0)|答案(1)|浏览(133)

我有一个UWP XAML <ListView>,我希望用户通过拖放来重新排列它。ListViewBase上的The CanReorderItems property提供了该功能,并且只需要几个属性:

<ListView ItemsSource="{x:Bind Items}"
    CanReorderItems="True"
    AllowDrop="True"
    DragItemsStarting="ListView_DragItemsStarting"
    DragItemsCompleted="ListView_DragItemsCompleted">
    <!-- ... -->
</ListView>

这成功地让我在ListView中拖放项目,并在ItemsSource上触发CollectionChanged事件(先移除再新增)。但是,它不会触发DragItemsStartingDragItemsCompleted事件。
这些事件使我可以原子地处理拖动,而不是依赖于ItemsSource中的两个CollectionChanged事件。
如何引发这些事件?
Disclaimer: I work for Microsoft.

gcmastyq

gcmastyq1#

ListView不会激发DragItemsStartingDragItemsCompleted事件,除非在ListView上将CanDragItems设置为true:

<ListView ItemsSource="{x:Bind Items}"
    CanDragItems="True"
    CanReorderItems="True"
    AllowDrop="True"
    DragItemsStarting="ListView_DragItemsStarting"
    DragItemsCompleted="ListView_DragItemsCompleted">
    <!-- ... -->
</ListView>

添加此属性后,您会发现这些事件将激发。

相关问题