我有一个MvxListView
绑定到集合的。当我第一次导航到 ViewModel 时,我从服务器加载数据并设置列表。视图加载得很好。
然后我设置了一个OnScroll
监听器,ListView
这样当用户滚动到底部时我可以加载下一页。我使用如下命令启动命令以获取结果的“下一页”:
this.ViewModel.ShowNextPageCommand.Execute(null);
该命令最终调用了一个方法,该方法使用 ViewModel 中的某些状态来获取下一页,所有这些都工作正常,但是当我实际去更新 ListView 绑定到的属性时,我收到以下错误 -
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Android.Util.AndroidRuntimeException: Exception of type 'Android.Util.AndroidRuntimeException' was thrown.
06-21 14:58:27.969 E/mono (28485): at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (IntPtr jobject, IntPtr jclass, IntPtr jmethod) [0x00023] in /Users/builder/data/lanes/monodroid-lion-bs1/0cc7ae3b/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:604
06-21 14:58:27.969 E/mono (28485): at Android.Widget.BaseAdapter.NotifyDataSetChanged () [0x00053] in /Users/builder/data/lanes/monodroid-lion-bs1/0cc7ae3b/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.Widget.BaseAdapter.cs:293
该属性如下所示:
private ICollection<Part> parts;
public ICollection<Part> Parts
{
get { return parts; }
set
{
this.parts = value;
RaisePropertyChanged(()=>Parts);
}
}
并且更新属性的代码如下所示:
private void HandlePartResults(PartsResults results)
{
if (this.Results == null)
{
this.Results = results;
this.Parts = results.Parts;
}
else
{
this.Results.Links.Clear();
this.Results.Links.AddRange(results.Links);
foreach (var part in results.Parts)
{
this.Results.Parts.Add(part);
}
Mvx.Trace(MvxTraceLevel.Diagnostic,Results.Parts.Count.ToString());
this.Parts = Results.Parts;
}
this.IsLoading = false;
}
我的布局如下所示:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/com.x3wire.mobile.android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
local:MvxBind="Visibility IsLoading,Converter=Visibility" />
<Mvx.MvxListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/PartResultsList"
local:MvxItemTemplate="@layout/partslistitem"
local:MvxBind="ItemsSource Parts; ItemClick ShowDetailCommand" />
</FrameLayout>
我也尝试过使用可观察的集合,但我得到了同样的异常。有什么明显的我做错了吗?