summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-06 12:15:32 (GMT)
committerRui Marinho <me@ruimarinho.net>2016-12-06 12:15:32 (GMT)
commit20e2e12dce2f81b92e8682f128cd81e08469f485 (patch)
tree965f0715dc24af3c0d0bd17740da9d962ed12927 /Xamarin.Forms.Core
parent10c65d035869fdc587f6ddddc0d472033af61ee6 (diff)
downloadxamarin-forms-20e2e12dce2f81b92e8682f128cd81e08469f485.zip
xamarin-forms-20e2e12dce2f81b92e8682f128cd81e08469f485.tar.gz
xamarin-forms-20e2e12dce2f81b92e8682f128cd81e08469f485.tar.bz2
[C] detach Behaviors and Triggers on VE finalization (#555)
* [C] detach Behaviors and Triggers on VE finalization * update docs
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 217f4a9..b5e4145 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 053ddb0..cff1eb1 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