使用UWP通过拖放来重新排序可绑定列表视图 [英] Reorder bindable listview by drag and drop using UWP

查看:67
本文介绍了使用UWP通过拖放来重新排序可绑定列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过拖放来重新排序ListView,它在使用静态项目时可以与我配合使用,但是当我使用 itemsSorce 绑定数据时,拖动效果很好,但是我可以删除这是我的代码的项目

I'm trying to reorder ListView by drag and drop,it work with me while am using static items, but when I bind the data using itemsSorce the drag work fine but i can't drop the item this is my code

C#:

lstSrvMenu.ItemsSource = Menue.MainItems.Where(m => int.Parse(m.GroupID) > 0);

XAML:

<ListView Name="lstSrvMenu" Margin="0,40,0,0" AllowDrop="True" CanDragItems="True" CanReorderItems="True" IsSwipeEnabled="true">
    <ListView.ItemTemplate>
      <DataTemplate>
         <TextBlock Text="{Binding GroupTDesc}" TextWrapping="WrapWholeWords" VerticalAlignment="Center" HorizontalAlignment="Left"/>
      </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

推荐答案

当我使用itemsSorce绑定数据时,拖动工作正常,但我不能删除该项目,这是我的代码.

when I bind the data using itemsSorce the drag work fine but i can't drop the item this is my code.

问题是ListView ItemSourse的类型不是

The problem is the type of ListView ItemSourse is not ObservableCollection . When you drag item completely, the sorting of the data source does not change, and the interface will not change accordingly. For your requirement, you could use ObservableCollection instead of List<>.

示例

var list = new ObservableCollection<string>();
for (var i = 0; i < 10; i++)
{
    list.Add(i.ToString() + "Template");
}
lstSrvMenu.ItemsSource = list;

这篇关于使用UWP通过拖放来重新排序可绑定列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆