问题
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