当 CanReorderItems 在 UWP ListView 上设置为 true 时,为什么我没有获得 DragItemsCompleted 和 DragItemsStarting 事件?

Why do I not get DragItemsCompleted and DragItemsStarting events when CanReorderItems is set to true on a UWP ListView?

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

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

这成功地让我在 ListView 中拖放项目并在 ItemsSource 上触发 CollectionChanged 事件(删除然后添加)。但是,它不会触发 DragItemsStartingDragItemsCompleted 事件。

这些事件让我可以自动处理拖动,而不是依赖来自 ItemsSource.

的两个 CollectionChanged 事件

如何触发这些事件?

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

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

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