diff --git a/src/Avalonia.Base/AvaloniaObject.cs b/src/Avalonia.Base/AvaloniaObject.cs
index baca1494be..761c0618da 100644
--- a/src/Avalonia.Base/AvaloniaObject.cs
+++ b/src/Avalonia.Base/AvaloniaObject.cs
@@ -29,12 +29,6 @@ namespace Avalonia
///
private IAvaloniaObject _inheritanceParent;
- ///
- /// The set values/bindings on this object.
- ///
- private readonly Dictionary _values =
- new Dictionary();
-
///
/// Maintains a list of direct property binding subscriptions so that the binding source
/// doesn't get collected.
@@ -52,6 +46,7 @@ namespace Avalonia
private EventHandler _propertyChanged;
private DeferredSetter _directDeferredSetter;
+ private ValueStore _values;
///
/// Delayed setter helper for direct properties. Used to fix #855.
@@ -228,9 +223,20 @@ namespace Avalonia
{
return ((IDirectPropertyAccessor)GetRegistered(property)).GetValue(this);
}
+ else if (_values != null)
+ {
+ var result = _values.GetValue(property);
+
+ if (result == AvaloniaProperty.UnsetValue)
+ {
+ result = GetDefaultValue(property);
+ }
+
+ return result;
+ }
else
{
- return GetValueInternal(property);
+ return GetDefaultValue(property);
}
}
@@ -257,7 +263,7 @@ namespace Avalonia
Contract.Requires(property != null);
VerifyAccess();
- return _values.TryGetValue(property, out PriorityValue value) ? value.IsAnimating : false;
+ return _values?.IsAnimating(property) ?? false;
}
///
@@ -274,14 +280,7 @@ namespace Avalonia
Contract.Requires(property != null);
VerifyAccess();
- PriorityValue value;
-
- if (_values.TryGetValue(property, out value))
- {
- return value.Value != AvaloniaProperty.UnsetValue;
- }
-
- return false;
+ return _values?.IsSet(property) ?? false;
}
///
@@ -369,14 +368,6 @@ namespace Avalonia
}
else
{
- PriorityValue v;
-
- if (!_values.TryGetValue(property, out v))
- {
- v = CreatePriorityValue(property);
- _values.Add(property, v);
- }
-
Logger.Verbose(
LogArea.Property,
this,
@@ -385,7 +376,12 @@ namespace Avalonia
description,
priority);
- return v.Add(source, (int)priority);
+ if (_values == null)
+ {
+ _values = new ValueStore(this);
+ }
+
+ return _values.AddBinding(property, source, priority);
}
}
@@ -416,20 +412,12 @@ namespace Avalonia
public void Revalidate(AvaloniaProperty property)
{
VerifyAccess();
- PriorityValue value;
-
- if (_values.TryGetValue(property, out value))
- {
- value.Revalidate();
- }
+ _values?.Revalidate(property);
}
///
- void IPriorityValueOwner.Changed(PriorityValue sender, object oldValue, object newValue)
+ void IPriorityValueOwner.Changed(AvaloniaProperty property, int priority, object oldValue, object newValue)
{
- var property = sender.Property;
- var priority = (BindingPriority)sender.ValuePriority;
-
oldValue = (oldValue == AvaloniaProperty.UnsetValue) ?
GetDefaultValue(property) :
oldValue;
@@ -439,7 +427,7 @@ namespace Avalonia
if (!Equals(oldValue, newValue))
{
- RaisePropertyChanged(property, oldValue, newValue, priority);
+ RaisePropertyChanged(property, oldValue, newValue, (BindingPriority)priority);
Logger.Verbose(
LogArea.Property,
@@ -448,14 +436,14 @@ namespace Avalonia
property,
oldValue,
newValue,
- priority);
+ (BindingPriority)priority);
}
}
///
- void IPriorityValueOwner.BindingNotificationReceived(PriorityValue sender, BindingNotification notification)
+ void IPriorityValueOwner.BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification)
{
- UpdateDataValidation(sender.Property, notification);
+ UpdateDataValidation(property, notification);
}
///
@@ -468,10 +456,7 @@ namespace Avalonia
/// Gets all priority values set on the object.
///
/// A collection of property/value tuples.
- internal IDictionary GetSetValues()
- {
- return _values;
- }
+ internal IDictionary GetSetValues() => _values?.GetSetValues();
///
/// Forces revalidation of properties when a property value changes.
@@ -660,68 +645,18 @@ namespace Avalonia
}
}
- ///
- /// Creates a for a .
- ///
- /// The property.
- /// The .
- private PriorityValue CreatePriorityValue(AvaloniaProperty property)
- {
- var validate = ((IStyledPropertyAccessor)property).GetValidationFunc(GetType());
- Func