Skip to content

fix(xaml): Apply x:Uid resw values to non-string properties (#17727)#23213

Open
MartinZikmund wants to merge 3 commits into
masterfrom
dev/mazi/navigateuriresource
Open

fix(xaml): Apply x:Uid resw values to non-string properties (#17727)#23213
MartinZikmund wants to merge 3 commits into
masterfrom
dev/mazi/navigateuriresource

Conversation

@MartinZikmund
Copy link
Copy Markdown
Member

Summary

  • The XAML source generator dropped x:Uid resource values for any property whose type wasn't String/Object (e.g., HyperlinkButton.NavigateUri of type Uri), because BuildInlineLocalizedProperties filtered candidate properties via IsLocalizablePropertyType. The user-reported case in [skia] HyperlinkButton does not work when the link is specified in NavigateUri a resource #17727 (clicking a HyperlinkButton with NavigateUri set via resw did nothing on Skia) is exactly this: the property was never assigned at runtime.
  • The fix iterates resw entries by uid (mirroring how BuildStatementLocalizedProperties handles attached properties) and wraps non-string values with XamlBindingHelper.ConvertValue so the runtime conversion (e.g., stringUri) is applied. For string/object properties the generated code is unchanged.

Test plan

  • Unit-test snapshots for the existing When_Xuid_Basic scenario remain unaffected (string property → identical generated code)
  • New runtime test in Given_xUid.When_xUid asserts HyperlinkButton.NavigateUri is set from resw (When_xUid_NavigateUri.NavigateUrihttps://platform.uno/)
  • Given_xUid.When_xUid and Given_xUid.When_xUid_On_Root pass on Skia Desktop runtime tests
  • WinUI parity is the issue's premise — the bug report itself confirms "Works on UWP/WinUI: Yes". The runtime test is gated #if !WINAPPSDK (uses Uno-specific WindowHelper), so /winui-runtime-tests cannot exercise it; WinUI's documented behavior was the target of this fix.

Closes #17727

🤖 Generated with Claude Code

x:Uid resources were silently dropped for properties whose type isn't
string/object (e.g., HyperlinkButton.NavigateUri of type Uri), because
the source generator filtered candidates via IsLocalizablePropertyType.
Iterate resw entries by uid like the attached-property path does, and
wrap non-string values with XamlBindingHelper.ConvertValue so the
runtime conversion (e.g., string -> Uri) is applied. This matches the
WinUI behavior on which the user-reported case relied.

Fixes #17727
Copilot AI review requested due to automatic review settings May 6, 2026 07:46
@github-actions github-actions Bot added the area/code-generation Categorizes an issue or PR as relevant to code generation label May 6, 2026
WindowHelper.WindowContent is supported on WinAppSDK; the #if !WINAPPSDK
guard was unnecessary and prevented WinUI parity validation for x:Uid.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Uno’s XAML source generator so x:Uid RESW values are applied to non-string properties (e.g., HyperlinkButton.NavigateUri), by emitting XamlBindingHelper.ConvertValue-based assignments for non-string property types. This resolves the Skia regression reported in #17727 where NavigateUri was never assigned at runtime.

Changes:

  • Update generated localization assignments to support non-string properties via runtime conversion.
  • Add a runtime test + XAML/RESW fixtures validating NavigateUri and Content are populated via x:Uid.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xUid.cs Adds runtime assertions for HyperlinkButton.NavigateUri and Content populated from RESW.
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/When_xUid.xaml Adds a HyperlinkButton with x:Uid to exercise non-string localization.
src/Uno.UI.RuntimeTests/Resources/en-US/Resources.resw Adds RESW entries for NavigateUri and Content for the new HyperlinkButton UID.
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs Changes inline localization generation to iterate RESW entries by UID and convert non-string values using XamlBindingHelper.ConvertValue.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3873 to +3884
foreach (var resource in _resourceDetailsCollection.FindByUId(objectUid))
{
var localizedValue = BuildLocalizedResourceValue(null, prop, objectUid);
if (localizedValue != null)
// The resource key is in the form "<uid>.<member>", or
// "<uid>.[using:<ns>]<type>.<property>" for attached properties.
var firstDotIndex = resource.Key.IndexOf('.');
if (firstDotIndex == -1)
{
ret = true;
if (isInInitializer)
{
writer.AppendLineInvariantIndented("{0} = {1},", prop, localizedValue);
}
else
{
writer.AppendLineInvariantIndented("{0} = {1};", prop, localizedValue);
}
continue;
}

var propertyPath = resource.Key.Substring(firstDotIndex + 1);

Match WinUI behavior in ObjectWriter::InitiatePropertyReplacementIfNeeded
where a resw entry replaces the XAML literal for any property type, not
just string/object. Wrap non-string resw values with
XamlBindingHelper.ConvertValue at codegen time.
Copilot AI review requested due to automatic review settings May 6, 2026 08:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_xUid.cs
@unodevops
Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 211121 has failed on Uno.UI - CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/code-generation Categorizes an issue or PR as relevant to code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[skia] HyperlinkButton does not work when the link is specified in NavigateUri a resource

3 participants