Browse Source

Merge pull request #12294 from Mrxx99/fix/attached-property-name-generation

Fix creating fields for attached properties called name. closes #12283
pull/12327/head
Max Katz 3 years ago
committed by GitHub
parent
commit
758c77f5f3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/tools/Avalonia.Generators/Common/XamlXNameResolver.cs
  2. 3
      tests/Avalonia.Generators.Tests/Views/NamedControl.xml
  3. 3
      tests/Avalonia.Generators.Tests/Views/xNamedControl.xml

6
src/tools/Avalonia.Generators/Common/XamlXNameResolver.cs

@ -38,6 +38,7 @@ internal class XamlXNameResolver : INameResolver, IXamlAstVisitor
{
if (child is XamlAstXamlPropertyValueNode propertyValueNode &&
propertyValueNode.Property is XamlAstNamePropertyReference namedProperty &&
!IsAttachedProperty(namedProperty) &&
namedProperty.Name == "Name" &&
propertyValueNode.Values.Count > 0 &&
propertyValueNode.Values[0] is XamlAstTextNode text)
@ -89,4 +90,9 @@ internal class XamlXNameResolver : INameResolver, IXamlAstVisitor
_ => _defaultFieldModifier
};
}
private static bool IsAttachedProperty(XamlAstNamePropertyReference namedProperty)
{
return !namedProperty.DeclaringType.Equals(namedProperty.TargetType);
}
}

3
tests/Avalonia.Generators.Tests/Views/NamedControl.xml

@ -2,6 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Sample.App.NamedControl">
<TextBox Name="UserNameTextBox"
AutomationProperties.Name="The user name"
Watermark="Username input"
UseFloatingWatermark="True" />
</Window>
</Window>

3
tests/Avalonia.Generators.Tests/Views/xNamedControl.xml

@ -2,6 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Sample.App.xNamedControl">
<TextBox x:Name="UserNameTextBox"
AutomationProperties.Name="The user name"
Watermark="Username input"
UseFloatingWatermark="True" />
</Window>
</Window>

Loading…
Cancel
Save