ios - Xamarin形式:导致指定参数的ListView不在有效值范围内。参数名称:索引

原文 标签 ios xamarin viewmodel indexoutofboundsexception

我尝试了很多组合来测试LoadData函数中的代码。

第一次加载Page时,调用LoadData函数。以后的用户更改日期,导致再次调用LoadData函数。这次在下面引用了一个错误。如果我注释了Collection = program行,则代码没有问题。

即使在函数的第二次执行中程序具有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的Stacktrace:

位于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.TemplatedItemsList 2 [TView,TItem] .OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)中:[0x0000a]在:0中
在Xamarin.Forms.Internals.TemplatedItemsList 2[TView,TItem].GroupedReset () [0x000b6] in <afec569c85894ae9a18371a2fecd2d37>:0 at Xamarin.Forms.Internals.TemplatedItemsList 2 [TView,TItem] .OnCollectionChangedGrouped(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)中:[0x00459]在:0中
在Xamarin.Forms.Internals.TemplatedItemsList 2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Boolean fixWindows) [0x00008] in <afec569c85894ae9a18371a2fecd2d37>:0 at Xamarin.Forms.Internals.TemplatedItemsList 2 [TView,TItem] .OnProxyCollectionChanged(System.Object发送者,System.Collections.Specialized.NotifyCollectionChangedEventArgs e)中,[0x00000]在:0中
在Xamarin.Forms.Internals.TemplatedItemsList 2[TView,TItem].OnItemsSourceChanged (System.Boolean fromGrouping) [0x00069] in <afec569c85894ae9a18371a2fecd2d37>:0 at Xamarin.Forms.Internals.TemplatedItemsList 2 [TView,TItem] .BindableOnPropertyChanged(System.Object sender,System.ComponentModel.PropertyChangedEventArgs e)[0x00020]在:0中
在(包装委托调用).invoke_void_object_PropertyChangedEventArgs(object,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当前应用,Xamarin.Forms.Internals.SetValueFlags属性,System.Boolean无提示)处[ 0x00107]在D:\ agent_work \ 1 \ s \ Xamarin.Forms.Core \ BindableObject.cs:602中
位于Da:\ 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
在Da:\ agent_work \ 1 \ s \ Xamarin.Forms中的Xamarin.Forms.BindingExpression.ApplyCore(System.Object sourceObject,Xamarin.Forms.BindableObject目标,Xamarin.Forms.BindableProperty属性,System.Boolean fromTarget)[0x001f9]中。核心\ BindingExpression.cs:172
在Xamarin.Forms.BindingExpression.Apply(System.Boolean fromTarget)[0x0003e]在D:\ agent_work \ 1 \ s \ Xamarin.Forms.Core \ BindingExpression.cs:56中
在Xamarin.Forms.BindingExpression + BindingExpressionPart.b__47_0()[0x00000]在D:\ agent_work \ 1 \ s \ Xamarin.Forms.Core \ BindingExpression.cs:557中
在/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.StringPrincipalClassName,System.String委托ClassName)[0x00038] /UIKit/UIApplication.cs:63
在/Users/simon/Documents/AimyPlus/EceAdmin/Tux/Tux.iOS/Main.cs:17中的Tux.iOS.Application.Main(System.String [] args)[0x00001]
> 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

最佳答案

这是更新的Xamarin.Forms 2.51444934的问题。进行分组列表视图时发生。为了解决:

ListView.HasUnevenRows = false;
ListView.IsGroupingEnabled = false;
((ObservableCollection<T>)listView.ItemsSource).Clear();
ListView.HasUnevenRows = true;
ListView.IsGroupingEnabled = true;

在替换新的数据收集之前,请放置类似的代码。该问题将得到解决。

相关文章:

ios - 需要有关自动布局的帮助

asp.net - 在 Controller 中更新 View 模型数据不会反映在 View 的输入字段中

c# - 如何使用嵌套类从特定的Model转换为ViewModel,反之亦然?

ios - 在领域中下载内容时如何更新progressView

ios - 删除对象时内存不释放-在ARC中释放的正确方法不清楚

ios - Facebook Graph API共享链接

android - RelativeLayout不遵守父边界

java - 使用相同的sqlite进行三个 Activity

c# - 在Xamarin Forms iOS应用中访问共享存储位置

wpf - WPF:用MVVM模式进行Tab控件的正确方法