【发布时间】:2012-04-07 20:51:09
【问题描述】:
当我运行以下测试时,我得到一个 ArgumentOutOfRangeException:
[TestClass]
public class ReproduceException
{
[TestMethod]
public void Doesnt_throw_when_adding_to_grouped_collection()
{
var collection = new ListCollectionView(new List<Test>());
collection.SortDescriptions.Add(new SortDescription("IsTrue", ListSortDirection.Ascending));
collection.GroupDescriptions.Add(new PropertyGroupDescription("Name"));
collection.AddNewItem(new Test() { Name = "Bob", IsTrue = false });
collection.CommitNew();
}
}
public class Test
{
public string Name { get; set; }
public bool IsTrue { get; set; }
}
我得到以下异常:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.ObjectModel.Collection`1.RemoveAt(Int32 index)
at System.Windows.Data.ListCollectionView.CommitNewForGrouping()
at System.Windows.Data.ListCollectionView.CommitNew()
我可能没有以正确的方式使用AddNewItem / CommitNew?
【问题讨论】: