* Ensure that the ListViewAdapter is no longer being used by the ListView before disposing it
* Remove `RemoveAllViews` from `Dispose`
{
internal class ListViewAdapter : CellAdapter
{
+ bool _disposed;
static readonly object DefaultItemTypeOrDataTemplate = new object();
const int DefaultGroupHeaderTemplateId = 0;
const int DefaultItemTemplateId = 1;
protected override void Dispose(bool disposing)
{
+ if (_disposed)
+ {
+ return;
+ }
+
+ _disposed = true;
+
if (disposing)
{
CloseContextActions();
_footerView?.Dispose();
_footerView = null;
+ // Unhook the adapter from the ListView before disposing of it
+ if (Control != null)
+ {
+ Control.Adapter = null;
+ }
+
if (_adapter != null)
{
_adapter.Dispose();
if (_adapter != null)
{
+ // Unhook the adapter from the ListView before disposing of it
+ if (Control != null)
+ {
+ Control.Adapter = null;
+ }
+
_adapter.Dispose();
_adapter = null;
}
}
}
- RemoveAllViews();
-
if (Element != null)
{
Element.PropertyChanged -= _propertyChangeHandler;