Skip to content

Commit

Permalink
fix(xamlreader): Take xmlns into account when resolvnig setter proper…
Browse files Browse the repository at this point in the history
…ties
  • Loading branch information
Youssef1313 committed Nov 21, 2023
1 parent 2d41b61 commit f8a273f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,40 @@ public void When_Input_Namespace()
var xaml = Windows.UI.Xaml.Markup.XamlReader.Load(xamlString);
Assert.IsInstanceOfType(xaml, typeof(StandardUICommand));
}

[TestMethod]
public void When_XMLNS()
{
var xamlString = """
<Style TargetType="FlyoutPresenter" xmlns:local="Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Markup">
<Setter Property="local:Given_AttachedDP.Prop" Value="1" />
</Style>
""";
var xaml = XamlHelper.LoadXaml<Style>(xamlString);
Assert.IsInstanceOfType(xaml, typeof(Style));
}
}

public static partial class Given_AttachedDP
{
public static void SetProp(this UIElement element, int prop)
{
element.SetValue(PropProperty, prop);
}

public static double GetProp(this UIElement element)
{
return (double)element.GetValue(PropProperty);
}

public static DependencyProperty PropProperty { get; } =
DependencyProperty.RegisterAttached(
"Prop",
typeof(int),
typeof(Given_AttachedDP),
new PropertyMetadata(0)
);

}

public class Given_XamlReader_CustomResDict : ResourceDictionary
Expand Down
18 changes: 17 additions & 1 deletion src/Uno.UI/UI/Xaml/Markup/Reader/XamlObjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,23 @@ private void AddCollectionItems(object collectionInstance, IEnumerable<XamlObjec
if (memberValue is { Length: > 0 } &&
PropertyPathPattern().Match(memberValue) is { Success: true, Groups: var g })
{
var declaringType = g["type"].Success ? TypeResolver.FindType(g["type"].Value) : _styleTargetTypeStack.Peek();
Type? declaringType;
if (g["type"].Success)
{
if (g["xmlns"].Success && g["xmlns"].Value is { } xmlns && xmlns.Length > 0)
{
declaringType = TypeResolver.FindType($"{xmlns}:{g["type"].Value}");
}
else
{
declaringType = TypeResolver.FindType(g["type"].Value);
}
}
else
{
declaringType = _styleTargetTypeStack.Peek();
}

var propertyName = g["property"].Value;

if (TypeResolver.FindDependencyProperty(declaringType, propertyName) is DependencyProperty property)
Expand Down

0 comments on commit f8a273f

Please sign in to comment.