diff --git a/src/Avalonia.Base/AvaloniaObject.cs b/src/Avalonia.Base/AvaloniaObject.cs
index 1b7bd91a8f..ee60bf5b78 100644
--- a/src/Avalonia.Base/AvaloniaObject.cs
+++ b/src/Avalonia.Base/AvaloniaObject.cs
@@ -29,11 +29,6 @@ namespace Avalonia
///
private IAvaloniaObject _inheritanceParent;
- ///
- /// The set values/bindings on this object.
- ///
- private readonly ValueStore _values;
-
///
/// Maintains a list of direct property binding subscriptions so that the binding source
/// doesn't get collected.
@@ -51,6 +46,7 @@ namespace Avalonia
private EventHandler _propertyChanged;
private DeferredSetter _directDeferredSetter;
+ private ValueStore _values;
///
/// Delayed setter helper for direct properties. Used to fix #855.
@@ -72,8 +68,6 @@ namespace Avalonia
{
VerifyAccess();
- _values = new ValueStore(this);
-
void Notify(AvaloniaProperty property)
{
object value = property.IsDirect ?
@@ -229,10 +223,14 @@ namespace Avalonia
{
return ((IDirectPropertyAccessor)GetRegistered(property)).GetValue(this);
}
- else
+ else if (_values != null)
{
return _values.GetValue(property);
}
+ else
+ {
+ return GetDefaultValue(property);
+ }
}
///
@@ -258,7 +256,7 @@ namespace Avalonia
Contract.Requires(property != null);
VerifyAccess();
- return _values.IsAnimating(property);
+ return _values?.IsAnimating(property) ?? false;
}
///
@@ -275,7 +273,7 @@ namespace Avalonia
Contract.Requires(property != null);
VerifyAccess();
- return _values.IsSet(property);
+ return _values?.IsSet(property) ?? false;
}
///
@@ -371,6 +369,11 @@ namespace Avalonia
description,
priority);
+ if (_values == null)
+ {
+ _values = new ValueStore(this);
+ }
+
return _values.AddBinding(property, source, priority);
}
}
@@ -402,7 +405,7 @@ namespace Avalonia
public void Revalidate(AvaloniaProperty property)
{
VerifyAccess();
- _values.Revalidate(property);
+ _values?.Revalidate(property);
}
///
@@ -446,7 +449,7 @@ namespace Avalonia
/// Gets all priority values set on the object.
///
/// A collection of property/value tuples.
- internal IDictionary GetSetValues() => _values.GetSetValues();
+ internal IDictionary GetSetValues() => _values?.GetSetValues();
///
/// Forces revalidation of properties when a property value changes.
@@ -642,7 +645,7 @@ namespace Avalonia
/// The default value.
internal object GetDefaultValue(AvaloniaProperty property)
{
- if (property.Inherits && InheritanceParent is AvaloniaObject aobj)
+ if (property.Inherits && InheritanceParent is AvaloniaObject aobj && aobj._values != null)
return aobj._values.GetValue(property);
return ((IStyledPropertyAccessor) property).GetDefaultValue(GetType());
}
@@ -726,7 +729,12 @@ namespace Avalonia
originalValue,
originalValue?.GetType().FullName ?? "(null)"));
}
-
+
+ if (_values == null)
+ {
+ _values = new ValueStore(this);
+ }
+
LogPropertySet(property, value, priority);
_values.AddValue(property, value, (int)priority);
}