diff --git a/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs b/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs index 20234cba2220..9cf6254624aa 100644 --- a/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs +++ b/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/Given_XamlReader.cs @@ -810,6 +810,28 @@ public void When_Resources_And_Empty() Assert.IsNotNull(r.Resources); } + [TestMethod] + public void When_StaticResource_And_NonDependencyProperty() + { + var app = UnitTestsApp.App.EnsureApplication(); + app.Resources["MyIntResource"] = 77; + try + { + var s = GetContent(nameof(When_StaticResource_And_NonDependencyProperty)); + var r = Windows.UI.Xaml.Markup.XamlReader.Load(s) as Page; + + var root = r.FindName("root") as Grid; + var inner = root.Children.First() as NonDependencyPropertyAssignable; + + Assert.AreEqual(77, inner.MyProperty); + } + finally + { + app.Resources.Remove("MyDoubleResource"); + } + + } + private string GetContent(string testName) { var assembly = this.GetType().Assembly; diff --git a/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/When_StaticResource_And_NonDependencyProperty.xamltest b/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/When_StaticResource_And_NonDependencyProperty.xamltest new file mode 100644 index 000000000000..1b161e736662 --- /dev/null +++ b/src/Uno.UI.Tests/Windows_UI_Xaml_Markup/XamlReaderTests/When_StaticResource_And_NonDependencyProperty.xamltest @@ -0,0 +1,11 @@ + + + + + + diff --git a/src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs b/src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs index 53c46de48dd7..f10c34e06449 100644 --- a/src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs +++ b/src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs @@ -251,7 +251,7 @@ private void ProcessNamedMember(XamlObjectDefinition control, object instance, X { if (IsMarkupExtension(member)) { - ProcessMemberMarkupExtension(instance, member); + ProcessMemberMarkupExtension(instance, member, propertyInfo); } else { @@ -278,7 +278,7 @@ private void ProcessNamedMember(XamlObjectDefinition control, object instance, X { if (IsMarkupExtension(member)) { - ProcessMemberMarkupExtension(instance, member); + ProcessMemberMarkupExtension(instance, member, null); } else if (instance is DependencyObject dependencyObject) { @@ -350,7 +350,7 @@ private void ProcessTextBlock(XamlObjectDefinition control, TextBlock instance, { if (IsMarkupExtension(member)) { - ProcessMemberMarkupExtension(instance, member); + ProcessMemberMarkupExtension(instance, member, null); } else { @@ -451,7 +451,7 @@ private void ProcessMemberElements(object instance, XamlMemberDefinition member, private static MethodInfo GetPropertySetter(PropertyInfo propertyInfo) => propertyInfo?.SetMethod ?? throw new InvalidOperationException($"Unable to find setter for property [{propertyInfo}]"); - private void ProcessMemberMarkupExtension(object instance, XamlMemberDefinition member) + private void ProcessMemberMarkupExtension(object instance, XamlMemberDefinition member, PropertyInfo propertyInfo) { if (IsBindingMarkupNode(member)) { @@ -459,11 +459,11 @@ private void ProcessMemberMarkupExtension(object instance, XamlMemberDefinition } else if (IsStaticResourceMarkupNode(member) || IsThemeResourceMarkupNode(member)) { - ProcessStaticResourceMarkupNode(instance, member); + ProcessStaticResourceMarkupNode(instance, member, propertyInfo); } } - private void ProcessStaticResourceMarkupNode(object instance, XamlMemberDefinition member) + private void ProcessStaticResourceMarkupNode(object instance, XamlMemberDefinition member, PropertyInfo propertyInfo) { var resourceNode = member.Objects.FirstOrDefault(); @@ -491,10 +491,12 @@ private void ProcessStaticResourceMarkupNode(object instance, XamlMemberDefiniti }; } } - else + else if (propertyInfo != null) { - // Here we assigned a {StaticResource} on a standard property (not a DependencyProperty) - // We can't resolve it. + GetPropertySetter(propertyInfo).Invoke( + instance, + new[] { ResourceResolver.ResolveResourceStatic(keyName, propertyInfo.PropertyType) } + ); } } }