xamarin - 如何解决 Xamarin.Forms.Platform.Android.ListViewAdapter.IsEnabled 异常?
问题描述
我有一个包含一些用户选定项目的列表。我的 CustumCellViewTemplate 有一个“取消选择”控件,它从列表中删除单元格。当列表完全充满项目时,“取消选择”控件起作用,但是当我想删除最后一个项目或最后一个项目出现在 ListView 中时,我得到了这个异常:
"System.NullReferenceException: Object reference not set to an instance of an object.
at Xamarin.Forms.Platform.Android.ListViewAdapter.IsEnabled (System.Int32 position) [0x0002a] in D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ListViewAdapter.cs:413
at Android.Widget.BaseAdapter.n_IsEnabled_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position) [0x00008] in <263adecfa58f4c449f1ff56156d886fd>:0
at (wrapper dynamic-method) System.Object.389216aa-a260-49e0-aaaa-e4e2031ad22f(intptr,intptr,int)"
这是我的配置:
Mono 8.1
Xamarin.Forms 3.3.0.893527-pre3
Xamarin.Android.Support.Design 27.0.2.1
Xamarin.Android.Support.v7.AppCompat 27.0.2.1
Xamarin.Android.Support.v4 27.0.2.1
Xamarin.Android.Support.v7.CardView 27.0.2.1
Xamarin.Android.Support.v7.MediaRouter 27.0.2.1
Xamarin.GooglePlayServices.Location 60.1142.1
Xamarin.GooglePlayServices.Maps 60.1142.1
Xamarin.Essentials 0.10.0-preview
请问您知道如何解决这个问题吗?
问候
解决方案
您现在可能已经解决了您的问题,但只是将其留给遇到此问题的其他人。
感谢 Jason 的问题,它让我清理了我对列表视图逻辑的可绑定 itemsource 的操作。我做了很多 .Clear() 和 Add 我不需要做的事情。我减少了这些的数量,它为我解决了这个问题。所以我会看看你是如何弄乱列表视图的 ItemSource 的。
推荐阅读
- javascript - react-datepicker 样式未应用于已部署的构建
- python-3.x - 如何用两个条件过滤 pandas.DataFrame
- spring - 如何向错误模板模型添加属性?
- database - Laravel 有更好的方法来编写我的数据库查询,也许是条件子句
- r - 当自变量移动一个常数时,断点相乘
- python - 从 .CSV 获取主题标签并在 Python 3 中计算它们
- angular8 - Angular8 Ivy 已启用:无法绑定到 'ngIf',因为它不是 'div' 的已知属性。”在任何文件保存时重新编译后
- python - 在相同的轴上绘制不同的 facecolor
- javascript - 使用 DOM 操作一次将鼠标悬停在一个元素上
- go - 如何在包含注释的情况下更新 AST 而不会破坏代码