gpt4 book ai didi

uwp - 使用拖放重新排序 ListView 中的项目

转载 作者:行者123 更新时间:2023-12-03 23:53:34 24 4
gpt4 key购买 nike

我尝试使用拖放手势重新排列 ListView 中的项目。

在“Drop”方法中我不知道如何获取对“dropped”元素的引用,我只获得了对“target drop”元素的引用。

见下文:

private void Grid_Drop(object sender, DragEventArgs e)
{
ReorderItem draggedElement = (e.OriginalSource as Grid).DataContext as ReorderItem;
ReorderItem targetElement = ((Grid)sender).DataContext as ReorderItem;

Debug.WriteLine("Dragged element is:" + draggedElement.Index);
Debug.WriteLine("Drag target element is:" + targetElement.Index);
}

重新排序介于 0 和 1 个索引之间。控制台索引都是 1 :(

<ListView ItemsSource="{Binding Items}" CanReorderItems="True">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Background="{Binding Color}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AllowDrop="True"
Drop="Grid_Drop">
</Grid>
</DataTemplate>
</ListView.ItemTemplate>

最佳答案

既然有人已经完成了,为什么还要重新发明轮子。查看 https://github.com/punker76/gong-wpf-dragdrop .它也可以作为 NuGet 包提供。

虽然文档使用 ListBox,但我将它与 ListView

一起使用

关于uwp - 使用拖放重新排序 ListView 中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22409416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com