|
|
@@ -32,8 +32,7 @@ namespace Avalonia
|
|
|
/// <summary>
|
|
|
/// The set values/bindings on this object.
|
|
|
/// </summary>
|
|
|
- private readonly Dictionary<AvaloniaProperty, PriorityValue> _values =
|
|
|
- new Dictionary<AvaloniaProperty, PriorityValue>();
|
|
|
+ private readonly ValueStore _values;
|
|
|
|
|
|
/// <summary>
|
|
|
/// Maintains a list of direct property binding subscriptions so that the binding source
|
|
|
@@ -73,6 +72,8 @@ namespace Avalonia
|
|
|
{
|
|
|
VerifyAccess();
|
|
|
|
|
|
+ _values = new ValueStore(this);
|
|
|
+
|
|
|
void Notify(AvaloniaProperty property)
|
|
|
{
|
|
|
object value = property.IsDirect ?
|
|
|
@@ -230,7 +231,7 @@ namespace Avalonia
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return GetValueInternal(property);
|
|
|
+ return _values.GetValue(property);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -257,7 +258,7 @@ namespace Avalonia
|
|
|
Contract.Requires<ArgumentNullException>(property != null);
|
|
|
VerifyAccess();
|
|
|
|
|
|
- return _values.TryGetValue(property, out PriorityValue value) ? value.IsAnimating : false;
|
|
|
+ return _values.IsAnimating(property);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -274,14 +275,7 @@ namespace Avalonia
|
|
|
Contract.Requires<ArgumentNullException>(property != null);
|
|
|
VerifyAccess();
|
|
|
|
|
|
- PriorityValue value;
|
|
|
-
|
|
|
- if (_values.TryGetValue(property, out value))
|
|
|
- {
|
|
|
- return value.Value != AvaloniaProperty.UnsetValue;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
+ return _values.IsSet(property);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -369,14 +363,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 +371,7 @@ namespace Avalonia
|
|
|
description,
|
|
|
priority);
|
|
|
|
|
|
- return v.Add(source, (int)priority);
|
|
|
+ return _values.AddBinding(property, source, priority);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -416,20 +402,12 @@ namespace Avalonia
|
|
|
public void Revalidate(AvaloniaProperty property)
|
|
|
{
|
|
|
VerifyAccess();
|
|
|
- PriorityValue value;
|
|
|
-
|
|
|
- if (_values.TryGetValue(property, out value))
|
|
|
- {
|
|
|
- value.Revalidate();
|
|
|
- }
|
|
|
+ _values.Revalidate(property);
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
- 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 +417,7 @@ namespace Avalonia
|
|
|
|
|
|
if (!Equals(oldValue, newValue))
|
|
|
{
|
|
|
- RaisePropertyChanged(property, oldValue, newValue, priority);
|
|
|
+ RaisePropertyChanged(property, oldValue, newValue, (BindingPriority)priority);
|
|
|
|
|
|
Logger.Verbose(
|
|
|
LogArea.Property,
|
|
|
@@ -448,14 +426,14 @@ namespace Avalonia
|
|
|
property,
|
|
|
oldValue,
|
|
|
newValue,
|
|
|
- priority);
|
|
|
+ (BindingPriority)priority);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
- void IPriorityValueOwner.BindingNotificationReceived(PriorityValue sender, BindingNotification notification)
|
|
|
+ void IPriorityValueOwner.BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification)
|
|
|
{
|
|
|
- UpdateDataValidation(sender.Property, notification);
|
|
|
+ UpdateDataValidation(property, notification);
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
@@ -468,10 +446,7 @@ namespace Avalonia
|
|
|
/// Gets all priority values set on the object.
|
|
|
/// </summary>
|
|
|
/// <returns>A collection of property/value tuples.</returns>
|
|
|
- internal IDictionary<AvaloniaProperty, PriorityValue> GetSetValues()
|
|
|
- {
|
|
|
- return _values;
|
|
|
- }
|
|
|
+ internal IDictionary<AvaloniaProperty, PriorityValue> GetSetValues() => _values.GetSetValues();
|
|
|
|
|
|
/// <summary>
|
|
|
/// Forces revalidation of properties when a property value changes.
|
|
|
@@ -660,68 +635,18 @@ namespace Avalonia
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Creates a <see cref="PriorityValue"/> for a <see cref="AvaloniaProperty"/>.
|
|
|
- /// </summary>
|
|
|
- /// <param name="property">The property.</param>
|
|
|
- /// <returns>The <see cref="PriorityValue"/>.</returns>
|
|
|
- private PriorityValue CreatePriorityValue(AvaloniaProperty property)
|
|
|
- {
|
|
|
- var validate = ((IStyledPropertyAccessor)property).GetValidationFunc(GetType());
|
|
|
- Func<object, object> validate2 = null;
|
|
|
-
|
|
|
- if (validate != null)
|
|
|
- {
|
|
|
- validate2 = v => validate(this, v);
|
|
|
- }
|
|
|
-
|
|
|
- PriorityValue result = new PriorityValue(
|
|
|
- this,
|
|
|
- property,
|
|
|
- property.PropertyType,
|
|
|
- validate2);
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Gets the default value for a property.
|
|
|
/// </summary>
|
|
|
/// <param name="property">The property.</param>
|
|
|
/// <returns>The default value.</returns>
|
|
|
- private object GetDefaultValue(AvaloniaProperty property)
|
|
|
+ internal object GetDefaultValue(AvaloniaProperty property)
|
|
|
{
|
|
|
if (property.Inherits && InheritanceParent is AvaloniaObject aobj)
|
|
|
- return aobj.GetValueInternal(property);
|
|
|
+ return aobj._values.GetValue(property);
|
|
|
return ((IStyledPropertyAccessor) property).GetDefaultValue(GetType());
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Gets a <see cref="AvaloniaProperty"/> value
|
|
|
- /// without check for registered as this can slow getting the value
|
|
|
- /// this method is intended for internal usage in AvaloniaObject only
|
|
|
- /// it's called only after check the property is registered
|
|
|
- /// </summary>
|
|
|
- /// <param name="property">The property.</param>
|
|
|
- /// <returns>The value.</returns>
|
|
|
- private object GetValueInternal(AvaloniaProperty property)
|
|
|
- {
|
|
|
- object result = AvaloniaProperty.UnsetValue;
|
|
|
- PriorityValue value;
|
|
|
-
|
|
|
- if (_values.TryGetValue(property, out value))
|
|
|
- {
|
|
|
- result = value.Value;
|
|
|
- }
|
|
|
-
|
|
|
- if (result == AvaloniaProperty.UnsetValue)
|
|
|
- {
|
|
|
- result = GetDefaultValue(property);
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
/// <summary>
|
|
|
/// Sets the value of a direct property.
|
|
|
/// </summary>
|
|
|
@@ -801,22 +726,9 @@ namespace Avalonia
|
|
|
originalValue,
|
|
|
originalValue?.GetType().FullName ?? "(null)"));
|
|
|
}
|
|
|
-
|
|
|
- PriorityValue v;
|
|
|
-
|
|
|
- if (!_values.TryGetValue(property, out v))
|
|
|
- {
|
|
|
- if (value == AvaloniaProperty.UnsetValue)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- v = CreatePriorityValue(property);
|
|
|
- _values.Add(property, v);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
LogPropertySet(property, value, priority);
|
|
|
- v.SetValue(value, (int)priority);
|
|
|
+ _values.AddValue(property, value, (int)priority);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|