首页 > 解决方案 > Switch order of item in Observable Collection - UWP

问题描述

Say I have 3 items in my observable collection and I want to swap the "indexes" of item1 (index of 1) and item2 (index of 2) so that item1 has an index of 2 and item2 has an index of 1. How easy is this to do? In needs to also be reflected in the UI where my ListView's itemsource is bound to the observable collection.

Thanks :)

标签: c#uwp

解决方案


ObservableCollection<T>有一个MoveItem(int oldIndex, int newIndex)功能。看这里https://docs.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1.moveitem?view=netframework-4.8


推荐阅读