Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 27, 2025

This PR adds documentation for directly assigning resource strings to XAML properties using the ms-resource URI scheme, addressing a gap in the current localization documentation.

Previously, the documentation only covered using the x:Uid directive for implicit property binding:

<TextBlock x:Uid="Greeting"/>

This change adds a new subsection "Direct property assignment using ms-resource" that explains how to explicitly assign resource strings to properties:

<TextBlock Text="ms-resource:///Resources/Farewell"/>

The new documentation covers:

  • Basic syntax for referencing string resources: ms-resource:///Resources/ResourceIdentifier
  • Examples for different resource files: ms-resource:///ErrorMessages/PasswordTooWeak
  • When to use direct assignment vs. the implicit x:Uid approach
  • Clear explanation that this provides more explicit control over resource assignment

This directly answers the user's question about what syntax to use for <TextBlock Text="{WHAT DO I PUT HERE TO GET RESOURCE STRING}" />.

Fixes #4724.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor

Learn Build status updates of commit 40be9fe:

⚠️ Validation status: warnings

For more details, please refer to the build report.

Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.

…I scheme

Co-authored-by: alvinashcraft <73072+alvinashcraft@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Doesn't cover assigning resource strings to properties Document direct property assignment using ms-resource URI scheme for UWP string resources Aug 27, 2025
Copilot finished work on behalf of alvinashcraft August 27, 2025 19:57
Copy link
Contributor

Learn Build status updates of commit f8c279a:

✅ Validation status: passed

File Status Preview URL Details
uwp/app-resources/localize-strings-ui-manifest.md ✅Succeeded

For more details, please refer to the build report.

@dotMorten
Copy link

dotMorten commented Aug 27, 2025

@alvinashcraft I was about to call you lazy :), but if the PR it made is correct (will have to test), I'm honestly impressed

Copy link

@dotMorten dotMorten left a comment

Choose a reason for hiding this comment

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

This approach described does not work

For example, if you had an "ErrorMessages.resw" file with a string resource identifier "PasswordTooWeak", you would reference it like this:

```xaml
<TextBlock Text="ms-resource:///ErrorMessages/PasswordTooWeak"/>

Choose a reason for hiding this comment

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

This of course doesn't work, since you can't place a Uri in a Text property. It would just write the text ms-resource:///ErrorMessages/PasswordTooWeak

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, you're correct. I wonder where the model is interpreting this info from. If I do a similar Bing search, the Copilot answer in my search results also tells me to do this. It's got the same example where it assigns it to the Text property.

Copy link

@dotMorten dotMorten Aug 28, 2025

Choose a reason for hiding this comment

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

The closest I've found an answer is this UWP answer: https://devblogs.microsoft.com/ifdef-windows/use-a-custom-resource-markup-extension-to-succeed-at-ui-string-globalization/
But first of all it doesn't work in WinUI 3 (sigh), and second, forcing you to set a global static property might work at the app level, but is completely broken for any class library trying to use resources, since there can be only one.

So far I've resorted to a custom markup extension but it really shouldn't be this hard to get resources into xaml.

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Must be. Well, I'm going to just close this PR and run the question by some folks on the product team to see if there are any other ideas. If not, it should probably be added as a feature request for WinUI/WASDK.

Choose a reason for hiding this comment

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

it should probably be added as a feature request for WinUI/WASDK.

Aw man... they are getting tired of me doing that 😀

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a NamedResource class in UWP/WinRT. I wonder if something like that would work if it were ported to WinAppSDK. You can set an ms-resource in its Uri property.

@alvinashcraft alvinashcraft deleted the copilot/fix-4724 branch August 28, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doesn't cover assigning resource strings to properties

3 participants