Skip to content

Commit 758c77f

Browse files
authored
Merge pull request #12294 from Mrxx99/fix/attached-property-name-generation
Fix creating fields for attached properties called name. closes #12283
2 parents 9d57ec0 + 73271b4 commit 758c77f

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ IXamlAstNode IXamlAstVisitor.Visit(IXamlAstNode node)
3838
{
3939
if (child is XamlAstXamlPropertyValueNode propertyValueNode &&
4040
propertyValueNode.Property is XamlAstNamePropertyReference namedProperty &&
41+
!IsAttachedProperty(namedProperty) &&
4142
namedProperty.Name == "Name" &&
4243
propertyValueNode.Values.Count > 0 &&
4344
propertyValueNode.Values[0] is XamlAstTextNode text)
@@ -89,4 +90,9 @@ private string TryGetFieldModifier(XamlAstObjectNode objectNode)
8990
_ => _defaultFieldModifier
9091
};
9192
}
93+
94+
private static bool IsAttachedProperty(XamlAstNamePropertyReference namedProperty)
95+
{
96+
return !namedProperty.DeclaringType.Equals(namedProperty.TargetType);
97+
}
9298
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
x:Class="Sample.App.NamedControl">
44
<TextBox Name="UserNameTextBox"
5+
AutomationProperties.Name="The user name"
56
Watermark="Username input"
67
UseFloatingWatermark="True" />
7-
</Window>
8+
</Window>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
x:Class="Sample.App.xNamedControl">
44
<TextBox x:Name="UserNameTextBox"
5+
AutomationProperties.Name="The user name"
56
Watermark="Username input"
67
UseFloatingWatermark="True" />
7-
</Window>
8+
</Window>

0 commit comments

Comments
 (0)