Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions uwp/app-resources/localize-strings-ui-manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ Instead of setting **Width** from a Resources File, you'll probably want to allo
Greeting.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name
```

### Direct property assignment using ms-resource

As an alternative to using **x:Uid**, you can directly assign a resource string to a property using the `ms-resource` URI scheme. This is useful when you want to explicitly set a specific property to a resource string without using the implicit property binding that **x:Uid** provides.

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

For the "Farewell" string resource identifier from our earlier example, the above markup would directly set the **Text** property of the **TextBlock** to the localized string value.

When using **ms-resource** for direct property assignment:
- Use the format `ms-resource:///Resources/ResourceIdentifier` for simple string resource identifiers
- The path `/Resources/` refers to the default `Resources.resw` file
- If you're using a different resource file name, replace `Resources` with your file name: `ms-resource:///YourFileName/ResourceIdentifier`

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.

```

This approach is particularly useful when you want to assign resource strings to properties that don't follow the standard naming convention used by **x:Uid**, or when you need more explicit control over which resource is assigned to which property.

## Refer to a string resource identifier from code

You can explicitly load a string resource based on a simple string resource identifier.
Expand Down