windows WinUI3 ListView获取放置项的位置

0x6upsns  于 2023-11-21  发布在  Windows
关注(0)|答案(1)|浏览(172)

有了ListView,我怎么才能得到列表中的索引,从同一个列表中的项目被删除?(重新排序)我尝试使用以下回调,但DragItemsCompletedEventArgsOnDropIntoStagedPhotos似乎都没有合适的方法。

  1. void TableContentPage::OnStagedDragItemsCompleted(
  2. [[maybe_unused]] ::winrt::Windows::Foundation::IInspectable const &,
  3. [[maybe_unused]] ::winrt::Microsoft::UI::Xaml::Controls::
  4. DragItemsCompletedEventArgs const &args)
  5. {
  6. }
  7. void TableContentPage::OnDropIntoStagedPhotos(
  8. [[maybe_unused]] Windows::Foundation::IInspectable const &sender,
  9. [[maybe_unused]] Microsoft::UI::Xaml::DragEventArgs const &args)
  10. {
  11. }

字符串
我使用以下ListView属性:

  1. <ListView x:Name="ListViewName"
  2. Grid.Row="0"
  3. Grid.Column="0"
  4. ScrollViewer.HorizontalScrollMode="Enabled"
  5. ScrollViewer.HorizontalScrollBarVisibility="Visible"
  6. ScrollViewer.IsHorizontalRailEnabled="True"
  7. CanDragItems="True"
  8. CanReorderItems="True"
  9. IsSwipeEnabled="True"
  10. HorizontalAlignment="Stretch"
  11. AllowDrop="True"
  12. Background="{StaticResource PrimaryColor}"
  13. Drop="OnDropIntoStagedPhotos"
  14. DragOver="OnDragOverStagedPhotos"
  15. DragItemsCompleted="OnStagedDragItemsCompleted"
  16. DragItemsStarting="OnStagedDragItemsStarting"
  17. SelectionMode="Extended"
  18. SelectionChanged="OnStagedPhotosSelectionChanged">

vngu2lb8

vngu2lb81#

ListViewBase.DragItemsCompleted给出了被拖动的项目,使用IVector.IndexOf,你可以检索索引。所以,我们只需要区分重新排序和移动。目的地有必要给出区别。
有一个UWP XamlDragAndDrop示例可以参考。

  1. /// <summary>
  2. /// Drop on the Trash
  3. /// </summary>
  4. /// <param name="sender"></param>
  5. /// <param name="e"></param>
  6. void Scenario1_ListView::TargetTextBlock_Drop(Platform::Object^ sender, Windows::UI::Xaml::DragEventArgs^ e)
  7. {
  8. if (e->DataView->Contains(StandardDataFormats::Text))
  9. {
  10. // We need to take the deferral as the source will read _deletedItem which
  11. // we cannot set synchronously
  12. auto def = e->GetDeferral();
  13. create_task(e->DataView->GetTextAsync()).then([this, e, def](String^ s)
  14. {
  15. _deletedItem = s;
  16. e->AcceptedOperation = DataPackageOperation::Move;
  17. def->Complete();
  18. });
  19. }
  20. }

字符串


的数据

展开查看全部

相关问题