if (!handled)
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
}
+
+ protected override bool ManageNativeControlLifetime => false;
}
}
\ No newline at end of file
{
if (disposing && !_disposed)
{
- if (Control != null)
+ if (Control != null && ManageNativeControlLifetime)
{
Control.RemoveFromParent();
Control.Dispose();
Performance.Stop();
}
+ /// <summary>
+ /// Determines whether the native control is disposed of when this renderer is disposed
+ /// Can be overridden in deriving classes
+ /// </summary>
+ protected virtual bool ManageNativeControlLifetime => true;
+
protected override void Dispose(bool disposing)
{
if ((_flags & VisualElementRendererFlags.Disposed) != 0)
_gestureListener = null;
}
- int count = ChildCount;
- for (var i = 0; i < count; i++)
+ if (ManageNativeControlLifetime)
{
- AView child = GetChildAt(i);
- child.Dispose();
+ int count = ChildCount;
+ for (var i = 0; i < count; i++)
+ {
+ AView child = GetChildAt(i);
+ child.Dispose();
+ }
}
RemoveAllViews();
if (e.OldElement == null)
SetNativeControl(Element.NativeView);
}
+
+ /// <summary>
+ /// The native control we're wrapping isn't ours to dispose of
+ /// </summary>
+ protected override bool ManageNativeControlLifetime => false;
}
}
\ No newline at end of file
return Control.SizeThatFits(size);
}
+ /// <summary>
+ /// Determines whether the native control is disposed of when this renderer is disposed
+ /// Can be overridden in deriving classes
+ /// </summary>
+ protected virtual bool ManageNativeControlLifetime => true;
+
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
- if (disposing && Control != null)
+ if (disposing && Control != null && ManageNativeControlLifetime)
{
Control.Dispose();
Control = null;