fix(xaml): Apply x:Uid resw values to non-string properties (#17727)#23213
Open
MartinZikmund wants to merge 3 commits into
Open
fix(xaml): Apply x:Uid resw values to non-string properties (#17727)#23213MartinZikmund wants to merge 3 commits into
MartinZikmund wants to merge 3 commits into
Conversation
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
WindowHelper.WindowContent is supported on WinAppSDK; the #if !WINAPPSDK guard was unnecessary and prevented WinUI parity validation for x:Uid.
Contributor
There was a problem hiding this comment.
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
NavigateUriandContentare populated viax: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.
Contributor
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
x:Uidresource values for any property whose type wasn'tString/Object(e.g.,HyperlinkButton.NavigateUriof typeUri), becauseBuildInlineLocalizedPropertiesfiltered candidate properties viaIsLocalizablePropertyType. The user-reported case in [skia] HyperlinkButton does not work when the link is specified in NavigateUri a resource #17727 (clicking aHyperlinkButtonwithNavigateUriset via resw did nothing on Skia) is exactly this: the property was never assigned at runtime.BuildStatementLocalizedPropertieshandles attached properties) and wraps non-string values withXamlBindingHelper.ConvertValueso the runtime conversion (e.g.,string→Uri) is applied. For string/object properties the generated code is unchanged.Test plan
When_Xuid_Basicscenario remain unaffected (string property → identical generated code)Given_xUid.When_xUidassertsHyperlinkButton.NavigateUriis set from resw (When_xUid_NavigateUri.NavigateUri→https://platform.uno/)Given_xUid.When_xUidandGiven_xUid.When_xUid_On_Rootpass on Skia Desktop runtime tests#if !WINAPPSDK(uses Uno-specificWindowHelper), so/winui-runtime-testscannot exercise it; WinUI's documented behavior was the target of this fix.Closes #17727
🤖 Generated with Claude Code