C# ReorderListBox中的InvalidOperationException?

C# ReorderListBox中的InvalidOperationException?,c#,windows-phone-8,windows-phone,reorderlist,C#,Windows Phone 8,Windows Phone,Reorderlist,我正在WP8应用程序中使用from。这是一件伟大的作品,值得高度赞赏 我正在为ReorderListBox设置ItemSource,如下所示: var Query = from it in AppDB.TableName select it; ReorderListBox.ItemsSource = Query.ToList(); 该列表完美地显示了项目,没有出现任何问题,但是当我重新排列列表时,出现了一个错误并中断了应

我正在WP8应用程序中使用from。这是一件伟大的作品,值得高度赞赏

我正在为ReorderListBox设置ItemSource,如下所示:

        var Query = from it in AppDB.TableName
                    select it;

        ReorderListBox.ItemsSource = Query.ToList();
该列表完美地显示了项目,没有出现任何问题,但是当我重新排列列表时,出现了一个错误并中断了应用程序。例外情况如下:

所以,它清楚地表明它不能在只读集合上工作。那么,如何使其适用于我的解决方案。我正在从sqlce数据库获取列表。

Query.ToList()
返回一个只读列表。尝试创建一个新列表,如

ReorderListBox.ItemsSource = new List<T>(Query.ToList());
ReorderListBox.ItemsSource=新列表(Query.ToList());
其中
T
TableName


但是,我认为您最好使用绑定,将ItemSource绑定到视图/视图模型中的
ObservableCollection
,然后将项目添加到该集合中。

我不知道该控件,但请记住,当您从列表中删除项目时,您可能还需要调整插入索引。