-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Document direct property assignment using ms-resource URI scheme for UWP string resources #5620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Learn Build status updates of commit 40be9fe:
|
…I scheme Co-authored-by: alvinashcraft <73072+alvinashcraft@users.noreply.github.com>
Learn Build status updates of commit f8c279a: ✅ Validation status: passed
For more details, please refer to the build report. |
@alvinashcraft I was about to call you lazy :), but if the PR it made is correct (will have to test), I'm honestly impressed |
There was a problem hiding this 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"/> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing it is getting it from here: https://learn.microsoft.com/en-us/windows/uwp/app-resources/uri-schemes#scheme-name-ms-resource
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😀
There was a problem hiding this comment.
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.
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:This change adds a new subsection "Direct property assignment using ms-resource" that explains how to explicitly assign resource strings to properties:
The new documentation covers:
ms-resource:///Resources/ResourceIdentifier
ms-resource:///ErrorMessages/PasswordTooWeak
x:Uid
approachThis 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.