summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r--Xamarin.Forms.Core/BindableObject.cs8
-rw-r--r--Xamarin.Forms.Core/VisualElement.cs13
2 files changed, 21 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/BindableObject.cs b/Xamarin.Forms.Core/BindableObject.cs
index 217f4a94..b5e41452 100644
--- a/Xamarin.Forms.Core/BindableObject.cs
+++ b/Xamarin.Forms.Core/BindableObject.cs
@@ -163,6 +163,14 @@ namespace Xamarin.Forms
return bpcontext != null && bpcontext.Binding != null;
}
+ internal bool GetIsDefault(BindableProperty targetProperty)
+ {
+ if (targetProperty == null)
+ throw new ArgumentNullException(nameof(targetProperty));
+
+ return GetContext(targetProperty) == null;
+ }
+
internal object[] GetValues(BindableProperty property0, BindableProperty property1)
{
var values = new object[2];
diff --git a/Xamarin.Forms.Core/VisualElement.cs b/Xamarin.Forms.Core/VisualElement.cs
index 053ddb0a..cff1eb10 100644
--- a/Xamarin.Forms.Core/VisualElement.cs
+++ b/Xamarin.Forms.Core/VisualElement.cs
@@ -781,5 +781,18 @@ namespace Xamarin.Forms
public bool Result { get; set; }
}
+
+ ~VisualElement()
+ {
+ if (!GetIsDefault(BehaviorsProperty)) {
+ var behaviors = GetValue(BehaviorsProperty) as AttachedCollection<Behavior>;
+ behaviors.DetachFrom(this);
+ }
+
+ if (!GetIsDefault(TriggersProperty)) {
+ var triggers = GetValue(TriggersProperty) as AttachedCollection<Trigger>;
+ triggers.DetachFrom(this);
+ }
+ }
}
} \ No newline at end of file