diff --git a/src/Avalonia.Base/AvaloniaObject.cs b/src/Avalonia.Base/AvaloniaObject.cs
index 0e2f0feada..94558c4367 100644
--- a/src/Avalonia.Base/AvaloniaObject.cs
+++ b/src/Avalonia.Base/AvaloniaObject.cs
@@ -208,20 +208,9 @@ 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 GetDefaultValue(property);
+ return GetValueOrDefaultUnchecked(property);
}
}
@@ -598,10 +587,46 @@ namespace Avalonia
private object GetDefaultValue(AvaloniaProperty property)
{
if (property.Inherits && InheritanceParent is AvaloniaObject aobj)
- return aobj.GetValue(property);
+ return aobj.GetValueOrDefaultUnchecked(property);
return ((IStyledPropertyAccessor) property).GetDefaultValue(GetType());
}
+ ///
+ /// Gets the value or default value for a property.
+ ///
+ /// The property.
+ /// The default value.
+ private object GetValueOrDefaultUnchecked(AvaloniaProperty property)
+ {
+ var aobj = this;
+ var valuestore = aobj._values;
+ if (valuestore != null)
+ {
+ var result = valuestore.GetValue(property);
+ if (result != AvaloniaProperty.UnsetValue)
+ {
+ return result;
+ }
+ }
+ if (property.Inherits)
+ {
+ while (aobj.InheritanceParent is AvaloniaObject parent)
+ {
+ aobj = parent;
+ valuestore = aobj._values;
+ if (valuestore != null)
+ {
+ var result = valuestore.GetValue(property);
+ if (result != AvaloniaProperty.UnsetValue)
+ {
+ return result;
+ }
+ }
+ }
+ }
+ return ((IStyledPropertyAccessor)property).GetDefaultValue(GetType());
+ }
+
///
/// Sets the value of a direct property.
///