diff --git a/src/Avalonia.Base/Controls/ResourceNodeExtensions.cs b/src/Avalonia.Base/Controls/ResourceNodeExtensions.cs
index 513b3f2424..1758c45650 100644
--- a/src/Avalonia.Base/Controls/ResourceNodeExtensions.cs
+++ b/src/Avalonia.Base/Controls/ResourceNodeExtensions.cs
@@ -40,19 +40,16 @@ namespace Avalonia.Controls
control = control ?? throw new ArgumentNullException(nameof(control));
key = key ?? throw new ArgumentNullException(nameof(key));
- IResourceHost? current = control;
+ IResourceNode? current = control;
while (current != null)
{
- if (current is IResourceHost host)
+ if (current.TryGetResource(key, out value))
{
- if (host.TryGetResource(key, out value))
- {
- return true;
- }
+ return true;
}
- current = (current as IStyledElement)?.StylingParent as IResourceHost;
+ current = (current as IStyledElement)?.StylingParent as IResourceNode;
}
value = null;
diff --git a/src/Avalonia.Base/Styling/IStyle.cs b/src/Avalonia.Base/Styling/IStyle.cs
index 78fbe0f2b5..738a69cb88 100644
--- a/src/Avalonia.Base/Styling/IStyle.cs
+++ b/src/Avalonia.Base/Styling/IStyle.cs
@@ -8,7 +8,7 @@ namespace Avalonia.Styling
///
/// Defines the interface for styles.
///
- public interface IStyle
+ public interface IStyle : IResourceNode
{
///
/// Gets a collection of child styles.
diff --git a/src/Avalonia.Base/Styling/Styles.cs b/src/Avalonia.Base/Styling/Styles.cs
index 81502f1570..d79081152e 100644
--- a/src/Avalonia.Base/Styling/Styles.cs
+++ b/src/Avalonia.Base/Styling/Styles.cs
@@ -160,7 +160,7 @@ namespace Avalonia.Styling
for (var i = Count - 1; i >= 0; --i)
{
- if (this[i] is IResourceProvider p && p.TryGetResource(key, out value))
+ if (this[i].TryGetResource(key, out value))
{
return true;
}
diff --git a/src/Avalonia.Themes.Default/Controls/DataValidationErrors.xaml b/src/Avalonia.Themes.Default/Controls/DataValidationErrors.xaml
index a3a4cf4662..d7bf4bbbf1 100644
--- a/src/Avalonia.Themes.Default/Controls/DataValidationErrors.xaml
+++ b/src/Avalonia.Themes.Default/Controls/DataValidationErrors.xaml
@@ -1,9 +1,13 @@
-
+
diff --git a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
index db33b88cc3..f865f87220 100644
--- a/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/MarkupExtensions/StaticResourceExtension.cs
@@ -39,17 +39,11 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
targetType = setter.Property.PropertyType;
}
- // Look upwards though the ambient context for IResourceHosts and IResourceProviders
+ // Look upwards though the ambient context for IResourceNodes
// which might be able to give us the resource.
- foreach (var e in stack.Parents)
+ foreach (var parent in stack.Parents)
{
- object value;
-
- if (e is IResourceHost host && host.TryGetResource(ResourceKey, out value))
- {
- return ColorToBrushConverter.Convert(value, targetType);
- }
- else if (e is IResourceProvider provider && provider.TryGetResource(ResourceKey, out value))
+ if (parent is IResourceNode node && node.TryGetResource(ResourceKey, out var value))
{
return ColorToBrushConverter.Convert(value, targetType);
}
@@ -58,7 +52,10 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions
if (provideTarget.TargetObject is IControl target &&
provideTarget.TargetProperty is PropertyInfo property)
{
- DelayedBinding.Add(target, property, x => GetValue(x, targetType));
+ var localTargetType = targetType;
+ var localInstance = this;
+
+ DelayedBinding.Add(target, property, x => localInstance.GetValue(x, localTargetType));
return AvaloniaProperty.UnsetValue;
}
diff --git a/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs b/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs
index 607b552c28..fa4a27fc50 100644
--- a/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/Styling/StyleInclude.cs
@@ -60,7 +60,7 @@ namespace Avalonia.Markup.Xaml.Styling
}
}
- bool IResourceNode.HasResources => (Loaded as IResourceProvider)?.HasResources ?? false;
+ bool IResourceNode.HasResources => Loaded?.HasResources ?? false;
IReadOnlyList IStyle.Children => _loaded ?? Array.Empty();
@@ -86,9 +86,9 @@ namespace Avalonia.Markup.Xaml.Styling
public bool TryGetResource(object key, out object? value)
{
- if (!_isLoading && Loaded is IResourceProvider p)
+ if (!_isLoading)
{
- return p.TryGetResource(key, out value);
+ return Loaded.TryGetResource(key, out value);
}
value = null;