我从xamarin开始,我在使用listview进行分组时遇到问题(IsGroupingEnabled = true)
当我像这样异步加载数据时引发System.ArgumentOutOfRangeException:
class RootMenuViewModel : BaseViewModel
{
public ObservableCollection<ItemClassification> Classif { get; set; }
public ObservableCollection<GroupItems> GroupedClassif { get; set; }
...
....
public async Task LoadDataAsync()
{
await Task.Run( () =>
{
authService.GetProfile( user =>
{
this.Email = user.Email;
dicoService.GetClassification(Settings.SystemId, Settings.ResourceId, classif => {
foreach (var item in classif)
{
if (item.ItemClass.Count>0)
{
GroupItems group = new GroupItems(item.Label);
foreach (var elt in item.ItemClass)
{
group.Add(elt); //creating groups raise exception
}
if(GroupedClassif.FirstOrDefault(x=>x.GroupName.Equals(group.GroupName))== null)
{
GroupedClassif.Add(group);
}
}
//Classif.Add(item);
}
});
});
});
}
}
Il从contentPage调用asynch加载:
protected override async void OnAppearing()
{
base.OnAppearing();
await rootUserProfileViewModel.LoadDataAsync();
}
这是堆栈跟踪:
未处理的例外:
System.ArgumentOutOfRangeException:索引超出范围。一定是 非负面且小于集合的大小。参数名称: 索引
02-15 10:12:00.948 I / MonoDroid(1856):UNHANDLED EXCEPTION:02-15 10:12:00.949 I / MonoDroid(1856):System.ArgumentOutOfRangeException: 指数超出范围。必须是非负数且小于 集合。 02-15 10:12:00.949 I / MonoDroid(1856):参数名称: 索引02-15 10:12:00.949 I / MonoDroid(1856):at(包装器 动态方法)System.Object:0336a8ee-fa98-462f-81c5-63d18afbbebd (intptr,intptr)02-15 10:12:00.949 I / MonoDroid(1856):at(包装) 托管到本机) Java.Interop.NativeMethods:java_interop_jnienv_call_nonvirtual_void_method_a (IntPtr的,IntPtr的&安培;,IntPtr的,IntPtr的,IntPtr的,Java.Interop.JniArgumentValue *) 02-15 10:12:00.949 I / MonoDroid(1856):at Java.Interop.JniEnvironment + InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference实例, Java.Interop.JniObjectReference类型,Java.Interop.JniMethodInfo 方法,Java.Interop.JniArgumentValue * args)[0x00073] in :0 02-15 10:12:00.949 I / MonoDroid( 1856):at Java.Interop.JniPeerMembers + JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember,Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue *参数)[0x0005d] in :0 02-15 10:12:00.949 I / MonoDroid( 1856):在Android.Widget.BaseAdapter.NotifyDataSetChanged() [0x0000a] in:0 02-15 10:12:00.949 I / MonoDroid(1856):at Xamarin.Forms.Platform.Android.ListViewAdapter.OnDataChanged() [0x00034] in d:\ agent_work \ 1 \ S \ Xamarin.Forms.Platform.Android \渲染器\ ListViewAdapter.cs:563 02-15 10:12:00.949 I / MonoDroid(1856):at Xamarin.Forms.Platform.Android.ListViewAdapter.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in d:\ agent_work \ 1 \ S \ Xamarin.Forms.Platform.Android \渲染器\ ListViewAdapter.cs:553 02-15 10:12:00.949 I / MonoDroid(1856):at Xamarin.Forms.Internals.TemplatedItemsList
2[TView,TItem].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in D:\agent\_work\1\s\Xamarin.Forms.Core\TemplatedItemsList.cs:771 02-15 10:12:00.949 I/MonoDroid( 1856): at Xamarin.Forms.Internals.TemplatedItemsList
2 [TView,TItem] .OnCollectionChangedGrouped (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x000d5] in D:\ agent_work \ 1 \ s \ Xamarin.Forms.Core \ TemplatedItemsList.cs:798 02-15 10:12:00.949 I / MonoDroid(1856):at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Boolean fixWindows) [0x00008] in D:\agent\_work\1\s\Xamarin.Forms.Core\TemplatedItemsList.cs:975 02-15 10:12:00.949 I/MonoDroid( 1856): at Xamarin.Forms.Internals.TemplatedItemsList
2 [TView,TItem] .OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in D:\ agent_work \ 1 \ s \ Xamarin.Forms.Core \ TemplatedItemsList.cs:968 02-15 10:12:00.949 I / MonoDroid(1856):at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) D:\ agent_work \ 1 \ s \ [Xamarin.Forms.Core \ ListProxy.cs中的[0x0000a]:233 02-15 10:12:00.949 I / MonoDroid(1856):at Xamarin.Forms.ListProxy + LT;&GT; c__DisplayClass33_0.b__0 ()[0x00018]在D:\ agent_work \ 1 \ s \ Xamarin.Forms.Core \ ListProxy.cs:206中 02-15 10:12:00.949 I / MonoDroid(1856):at Java.Lang.Thread + RunnableImplementor.Run()[0x00008] in :0 02-15 10:12:00.949 I / MonoDroid( 1856):在Java.Lang.IRunnableInvoker.n_Run(System.IntPtr jnienv, System.IntPtr native__this)[0x00008] in :0 02-15 10:12:00.949 I / MonoDroid( 1856):at(包装动态方法) System.Object:61a7ea3b-2ffa-42ea-8ca3-d33b76f002b8(intptr,intptr)
提前谢谢