Reorder bindable listview by drag and drop using UWP

梦想与她 提交于 2019-12-13 17:30:59

问题


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>

回答1:


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

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<>.

Example

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



来源:https://stackoverflow.com/questions/46522556/reorder-bindable-listview-by-drag-and-drop-using-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!