diff --git a/src/Perspex.Base/PerspexObject.cs b/src/Perspex.Base/PerspexObject.cs
index 0f28f598d8..ccc5f34072 100644
--- a/src/Perspex.Base/PerspexObject.cs
+++ b/src/Perspex.Base/PerspexObject.cs
@@ -23,17 +23,6 @@ namespace Perspex
///
public class PerspexObject : IPerspexObject, IPerspexObjectDebug, INotifyPropertyChanged, IPriorityValueOwner
{
- ///
- /// Maintains a list of direct property binding subscriptions so that the binding source
- /// doesn't get collected.
- ///
- ///
- /// If/when we provide a ClearBindings() method, then this collection will be need to be
- /// moved to an instance field and indexed by property, but until that point a static
- /// collection will suffice.
- ///
- private static List s_directBindings = new List();
-
///
/// The parent object that inherited values are inherited from.
///
@@ -45,6 +34,12 @@ namespace Perspex
private readonly Dictionary _values =
new Dictionary();
+ ///
+ /// Maintains a list of direct property binding subscriptions so that the binding source
+ /// doesn't get collected.
+ ///
+ private List _directBindings;
+
///
/// Event handler for implementation.
///
@@ -402,17 +397,22 @@ namespace Perspex
IDisposable subscription = null;
+ if (_directBindings == null)
+ {
+ _directBindings = new List();
+ }
+
subscription = source
.Select(x => CastOrDefault(x, property.PropertyType))
- .Do(_ => { }, () => s_directBindings.Remove(subscription))
+ .Do(_ => { }, () => _directBindings.Remove(subscription))
.Subscribe(x => DirectBindingSet(property, x));
- s_directBindings.Add(subscription);
+ _directBindings.Add(subscription);
return Disposable.Create(() =>
{
subscription.Dispose();
- s_directBindings.Remove(subscription);
+ _directBindings.Remove(subscription);
});
}
else