From 9e8b56a07cb2983f1a632525d8518008a184769e Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 3 Jan 2025 23:39:04 +0900 Subject: [PATCH 1/3] fix: Ensure x:Uid is set only when both name and namespace are correct --- .../Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs index b422b1f943d8..1bbdf5bde53e 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs @@ -3328,7 +3328,8 @@ private void BuildExtendedProperties(IIndentedStringBuilder outerwriter, XamlObj { writer.AppendLineInvariantIndented("// Load {0}", member.Value); } - else if (member.Member.Name == "Uid") + else if (member.Member.Name == "Uid" + && member.Member.PreferredXamlNamespace == XamlConstants.XamlXmlNamespace) { uidMember = member; writer.AppendLineIndented($"{GlobalPrefix}Uno.UI.Helpers.MarkupHelper.SetXUid({closureName}, \"{objectUid}\");"); From de9635a830908f6c970f10c7e6bffefe5e15df5c Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 3 Jan 2025 23:39:43 +0900 Subject: [PATCH 2/3] test: x:Uid and attached property Uid conflict --- .../Resources/en-US/Resources.resw | 3 ++ ...licts_With_AttachedProperty_Named_Uid.xaml | 20 ++++++++ ...ts_With_AttachedProperty_Named_Uid.xaml.cs | 51 +++++++++++++++++++ .../Tests/Windows_UI_Xaml/Given_xUid.cs | 9 ++++ 4 files changed, 83 insertions(+) create mode 100644 src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid_Conflicts_With_AttachedProperty_Named_Uid.xaml create mode 100644 src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid_Conflicts_With_AttachedProperty_Named_Uid.xaml.cs diff --git a/src/Uno.UI.RuntimeTests/Resources/en-US/Resources.resw b/src/Uno.UI.RuntimeTests/Resources/en-US/Resources.resw index b55d0f362539..bf7d1b679604 100644 --- a/src/Uno.UI.RuntimeTests/Resources/en-US/Resources.resw +++ b/src/Uno.UI.RuntimeTests/Resources/en-US/Resources.resw @@ -129,4 +129,7 @@ en-US Value for When_xUid_Root.Title + + en-US Value for When_xUid_Conflicts_With_AttachedProperty_Named_Uid + \ No newline at end of file diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid_Conflicts_With_AttachedProperty_Named_Uid.xaml b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid_Conflicts_With_AttachedProperty_Named_Uid.xaml new file mode 100644 index 000000000000..3d946b503f8d --- /dev/null +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid_Conflicts_With_AttachedProperty_Named_Uid.xaml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid_Conflicts_With_AttachedProperty_Named_Uid.xaml.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid_Conflicts_With_AttachedProperty_Named_Uid.xaml.cs new file mode 100644 index 000000000000..6a53222e1531 --- /dev/null +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid_Conflicts_With_AttachedProperty_Named_Uid.xaml.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Windows.Foundation; +using Windows.Foundation.Collections; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; + +// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 + +namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls +{ + public static class Uids + { + public static readonly DependencyProperty UidProperty = DependencyProperty.RegisterAttached( + "Uid", + typeof(string), + typeof(Uids), + new PropertyMetadata(default)); + + public static string GetUid(DependencyObject dependencyObject) + { + return (string)dependencyObject.GetValue(UidProperty); + } + + public static void SetUid(DependencyObject dependencyObject, string uid) + { + dependencyObject.SetValue(UidProperty, uid); + } + } + + public sealed partial class When_xUid_Conflicts_With_AttachedProperty_Named_Uid : UserControl + { + public When_xUid_Conflicts_With_AttachedProperty_Named_Uid() + { + this.InitializeComponent(); + Loaded += When_xUid_Has_Name_Conflict_Loaded; + } + + private void When_xUid_Has_Name_Conflict_Loaded(object sender, RoutedEventArgs e) + { + } + } +} diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xUid.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xUid.cs index ff920f048b54..5ecaa8972bfb 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xUid.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xUid.cs @@ -34,5 +34,14 @@ public void When_xUid_On_Root() var SUT = new When_xUid_On_Root(); Assert.AreEqual("en-US Value for When_xUid_Root.Title", SUT.Title); } + + [TestMethod] + public void When_xUid_Conflicts_With_AttachedProperty_Named_Uid() + { + var SUT = new When_xUid_Conflicts_With_AttachedProperty_Named_Uid(); + Assert.AreEqual("en-US Value for When_xUid_Conflicts_With_AttachedProperty_Named_Uid", SUT.xUidTextBlock.Text); + var attachedPropertyUidValue = Uids.GetUid(SUT.attachedPropertyUidTextBlock); + Assert.AreEqual("AttachedPropertyUid", attachedPropertyUidValue); + } } #endif From 7ec9cd216840e21d843c6c84e21baf76604c45be Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Wed, 15 Jan 2025 22:47:36 +0900 Subject: [PATCH 3/3] fix: Update GetObjectUid to also check Uid namespace --- .../Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs index 1bbdf5bde53e..55cef9e60ab9 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs @@ -5883,7 +5883,7 @@ internal static bool IsLocalizablePropertyType(INamedTypeSymbol? propertyType) private string? GetObjectUid(XamlObjectDefinition objectDefinition) { string? objectUid = null; - var localizedObject = FindMember(objectDefinition, "Uid"); + var localizedObject = FindMember(objectDefinition, "Uid", XamlConstants.PresentationXamlXmlNamespace); if (localizedObject?.Value != null) { objectUid = localizedObject.Value.ToString();