|
|
@ -32,7 +32,7 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
var schemaContext = context.GetService<IXamlSchemaContextProvider>()?.SchemaContext; |
|
|
var schemaContext = context.GetService<IXamlSchemaContextProvider>()?.SchemaContext; |
|
|
var ambientProvider = context.GetService<IAmbientProvider>(); |
|
|
var ambientProvider = context.GetService<IAmbientProvider>(); |
|
|
var resourceProviderType = schemaContext.GetXamlType(typeof(IResourceProvider)); |
|
|
var resourceProviderType = schemaContext.GetXamlType(typeof(IResourceProvider)); |
|
|
var resourceProviders = ambientProvider.GetAllAmbientValues(resourceProviderType); |
|
|
var ambientValues = ambientProvider.GetAllAmbientValues(resourceProviderType); |
|
|
|
|
|
|
|
|
// Look upwards though the ambient context for IResourceProviders which might be able
|
|
|
// Look upwards though the ambient context for IResourceProviders which might be able
|
|
|
// to give us the resource.
|
|
|
// to give us the resource.
|
|
|
@ -43,18 +43,23 @@ namespace Avalonia.Markup.Xaml.MarkupExtensions |
|
|
//
|
|
|
//
|
|
|
// StaticResource_Can_Be_Assigned_To_Property_In_ControlTemplate_In_Styles_File
|
|
|
// StaticResource_Can_Be_Assigned_To_Property_In_ControlTemplate_In_Styles_File
|
|
|
//
|
|
|
//
|
|
|
foreach (IResourceProvider resourceProvider in resourceProviders) |
|
|
foreach (var ambientValue in ambientValues) |
|
|
{ |
|
|
{ |
|
|
if (resourceProvider is IControl control && control.StylingParent != null) |
|
|
// We override XamlType.CanAssignTo in BindingXamlType so the results we get back
|
|
|
|
|
|
// from GetAllAmbientValues aren't necessarily of the correct type.
|
|
|
|
|
|
if (ambientValue is IResourceProvider resourceProvider) |
|
|
{ |
|
|
{ |
|
|
// If we've got to a control that has a StylingParent then it's probably
|
|
|
if (resourceProvider is IControl control && control.StylingParent != null) |
|
|
// a top level control and its StylingParent is pointing to the global
|
|
|
{ |
|
|
// styles. If this is case just do a FindResource on it.
|
|
|
// If we've got to a control that has a StylingParent then it's probably
|
|
|
return control.FindResource(ResourceKey); |
|
|
// a top level control and its StylingParent is pointing to the global
|
|
|
} |
|
|
// styles. If this is case just do a FindResource on it.
|
|
|
else if (resourceProvider.TryGetResource(ResourceKey, out var value)) |
|
|
return control.FindResource(ResourceKey); |
|
|
{ |
|
|
} |
|
|
return value; |
|
|
else if (resourceProvider.TryGetResource(ResourceKey, out var value)) |
|
|
|
|
|
{ |
|
|
|
|
|
return value; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|