【发布时间】:2018-10-03 05:11:37
【问题描述】:
我尝试了很多组合来测试LoadData函数中的代码。
第一次加载页面时,LoadData 函数被调用。后来用户更改了导致再次调用LoadData 函数的日期。这次出现了下面引用的错误。如果我注释了 Collection = 程序行,则代码没有问题。
即使程序在函数的第二次执行中有 0 项的问题。
public async Task LoadData (DateTime day)
{
this.day = day;
var programs = await new ECEProgramLogic().GetGrouppedProgram(day.Date, actionNameType);
Collection = programs;
}
private ObservableCollection<GroupViewModel<object>> collection;
public ObservableCollection<GroupViewModel<object>> Collection
{
get
{
return collection;
}
set
{
collection = value;
Banner = new NoDataBannerViewModel<GroupViewModel<object>>(value, AppResources.NoDataToShow);
OnPropertyChanged(nameof(Collection));
}
}
指定的参数超出了有效值的范围。范围 名称:索引
来自 Xamarin 的堆栈跟踪:
在 D:\agent_work\1\s\Xamarin.Forms.Core\ListProxy.cs:127 中的 Xamarin.Forms.ListProxy.get_Item(System.Int32 索引)[0x0000b] 在 D:\agent_work\1\s\Xamarin.Forms.Core\ListProxy.cs:444 中的 Xamarin.Forms.ListProxy.System.Collections.IList.get_Item(System.Int32 索引)[0x00000] 在 Xamarin.Forms.Internals.TemplatedItemsList
2[TView,TItem].get_Item (System.Int32 index) [0x00008] in <afec569c85894ae9a18371a2fecd2d37>:0 at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.HeaderViewDisplayingEnded (UIKit.UITableView tableView, UIKit.UIView headerView, System.nint section) [0x0001f] in <82f6100a289642ae988dc0d85a373bef>:0 at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend(intptr,intptr) at UIKit.UITableView.ReloadData () [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/UIKit/UITableView.g.cs:792 at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateItems (System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Int32 section, System.Boolean resetWhenGrouped) [0x002b8] in <82f6100a289642ae988dc0d85a373bef>:0 at Xamarin.Forms.Platform.iOS.ListViewRenderer.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <82f6100a289642ae988dc0d85a373bef>:0 at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] 在:0 在 Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].GroupedReset () [0x000b6] in <afec569c85894ae9a18371a2fecd2d37>:0 at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnCollectionChangedGrouped (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00459] 在:0 在 Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Boolean fixWindows) [0x00008] in <afec569c85894ae9a18371a2fecd2d37>:0 at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnProxyCollectionChanged(System.Object 发件人,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)[0x00000] 在:0 在 Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnItemsSourceChanged (System.Boolean fromGrouping) [0x00069] in <afec569c85894ae9a18371a2fecd2d37>:0 at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].BindableOnPropertyChanged(System.Object 发件人,System.ComponentModel.PropertyChangedEventArgs e)[0x00020] 在:0 在(包装委托调用).invoke_void_object_PropertyChangedEventArgs(对象,System.ComponentModel.PropertyChangedEventArgs) 在 D:\agent_work\1\s\Xamarin.Forms.Core\BindableObject.cs:146 中的 Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] 在 D:\agent_work\1\s\Xamarin.Forms.Core\Element.cs:401 中的 Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] 在 Xamarin.Forms.BindableObject.SetValueActual(Xamarin.Forms.BindableProperty 属性,Xamarin.Forms.BindableObject+BindablePropertyContext 上下文,System.Object 值,System.Boolean currentApplying,Xamarin.Forms.Internals.SetValueFlags 属性,System.Boolean 无声)[ 0x00107] 在 D:\agent_work\1\s\Xamarin.Forms.Core\BindableObject.cs:602 在 D:\agent_work\1\ 中的 Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty 属性、System.Object 值、Xamarin.Forms.Internals.SetValueFlags 属性、Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)[0x0015b] s\Xamarin.Forms.Core\BindableObject.cs:399 在 D:\agent_work\1\s\Xamarin.Forms 中的 Xamarin.Forms.BindingExpression.ApplyCore(System.Object sourceObject,Xamarin.Forms.BindableObject 目标,Xamarin.Forms.BindableProperty 属性,System.Boolean fromTarget)[0x001f9]。核心\绑定表达式.cs:172 在 D:\agent_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:56 中的 Xamarin.Forms.BindingExpression.Apply(System.Boolean fromTarget)[0x0003e] 在 D:\agent_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:557 中的 Xamarin.Forms.BindingExpression+BindingExpressionPart.b__47_0 () [0x00000] 在 /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/Foundation/NSAction.cs:163 中的 Foundation.NSAsyncActionDispatcher.Apply () [0x00000] 在(包装器托管到本机)UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) 在 /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS 中的 UIKit.UIApplication.Main(System.String[] args,System.IntPtr 主体,System.IntPtr 委托)[0x00005] /UIKit/UIApplication.cs:79 在 /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS 中的 UIKit.UIApplication.Main (System.String [] args, System.String principalClassName, System.String delegateClassName) [0x00038] /UIKit/UIApplication.cs:63 在 Tux.iOS.Application.Main (System.String[] args) [0x00001] 在 /Users/simon/Documents/AimyPlus/EceAdmin/Tux/Tux.iOS/Main.cs:17
> Xamarin.Android
Version: 8.2.0.16 (Visual Studio Community)
Android SDK: /Users/simon/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
6.0 (API level 23)
7.1 (API level 25)
8.0 (API level 26)
SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.5
SDK Build Tools Version: 25.0.3
Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Xamarin Inspector
Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1
Apple Developer Tools
Xcode 9.2 (13772)
Build 9C40b
Xamarin.Mac
Version: 4.2.1.28 (Visual Studio Community)
Xamarin.iOS
Version: 11.9.1.24 (Visual Studio Community)
Hash: f62de472
Branch: xcode9.3
Build date: 2018-03-29 19:30:53-0400
【问题讨论】:
-
尝试将属性名称
Collection更改为另一个名称,可能System.Collections.ObjectModel.Collection和您的属性名称之间存在混淆 -
我尝试将 Collection 更改为 Collectionff 但仍然有问题....
-
有什么区别!尝试将其更改为
CollectionData或类似的东西。 -
抱歉我的 f 键不太好
-
你能指定你工作的 Xamarin 鹿肉吗
标签: ios xamarin viewmodel indexoutofboundsexception