xaml - 当 UWP ListView 上的 CanReorderItems 设置为 true 时,为什么我没有得到 DragItemsCompleted 和 DragItemsStarting 事件?
问题描述
我有一个 UWP XAML <ListView>
,我希望用户通过拖放重新排列。ListViewBase 上的CanReorderItems
属性提供了该功能,并且只需要几个属性:
<ListView ItemsSource="{x:Bind Items}"
CanReorderItems="True"
AllowDrop="True"
DragItemsStarting="ListView_DragItemsStarting"
DragItemsCompleted="ListView_DragItemsCompleted">
<!-- ... -->
</ListView>
这成功地让我在 ListView 中拖放项目并在(删除然后添加)上触发CollectionChanged
事件。ItemsSource
但是,它不会触发DragItemsStarting
andDragItemsCompleted
事件。
CollectionChanged
这些事件让我可以原子地处理拖动,而不是依赖ItemsSource
.
如何让这些事件触发?
解决方案
ListView
s 不会触发DragItemsStarting
和DragItemsCompleted
事件,除非CanDragItems
在 ListView 上设置为 true:
<ListView ItemsSource="{x:Bind Items}"
CanDragItems="True"
CanReorderItems="True"
AllowDrop="True"
DragItemsStarting="ListView_DragItemsStarting"
DragItemsCompleted="ListView_DragItemsCompleted">
<!-- ... -->
</ListView>
添加此属性后,您应该会发现这些事件将触发。
推荐阅读
- vba - filename.csv 的文件格式和扩展名不匹配
- vba - VBA遍历工作簿中的工作表
- css - CSS 样式化 div 类中的链接
- c++ - 从自身内部替换 std::function (通过移动分配到 *this?)
- reactjs - React 代码执行优先级问题
- ios - 在 Swift iOS 中根据单元格的偶数和奇数索引设计 UICollectionViewCell
- java - Apache Mina 通过 Windows 服务器上的 SSH 限制用户
- django - 如何在权限自定义装饰器中发送 HttpResponse?
- database - 我应该使用什么软件来进行图形分布式存储和处理?
- java - 在 Oreo 上单击带有 EditText 的 FAB 时出现 IndexOutOfBoundsException