How to load local strings from a Class Library or a Windows Runtime Library in Xaml with u:id

华 张 136 Reputation points
2021-09-02T15:24:54.48+00:00

I found a method "Load strings from a Class Library or a Windows Runtime Library" in the .cs file, like this: https://learn.microsoft.com/en-us/windows/uwp/app-resources/localize-strings-ui-manifest, but how to do it in Xaml with u: id.

u: id now works only if you place localization strings files in the same class library as Xaml, what can I do?

It took a long long time to find a way, but can not find it.

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. 华 张 136 Reputation points
    2021-09-13T14:27:01.523+00:00

    I have solved this problem by setting a custom attached property.

    you can do it:

    var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView("ContosoControl/Resources");
    this.myXAMLTextBlockElement.Text = resourceLoader.GetString("exampleResourceName");

    get a text from the .resw file

    then you can set a value on your control