I am writing a win8 application and will be using the built-in resource management system: resw
file and x:Uid
tags in my XAML code.
So I create let's say a TextBox
like that:
<TextBlock Style="{StaticResource HeaderTextStyle}" x:Uid="ResourceTest"/>
I create the corresponding resource file in my assembly with a ResourceTest.Text
entry and it works fine: proper text is displayed at runtime.
Now, I would like to move all my resx files to another C# Library for maintainability. So I put the resources file in a brand new project and reference this new assembly from the main assembly.
But this causes the previous construct to fail (no text is displayed).
However, if I programmatically retrieve the resource value using the following code from inside the side assembly (called ResourcesLibrary), I get the string correctly:
static ResourceLoader resourceLoader = null;
public static string GetString(string resourceName)
{
if (resourceLoader == null)
resourceLoader = new ResourceLoader ("ResourcesLibrary/Resources");
return resourceLoader.GetString (resourceName);
}
How do I enable the x:Uid
mechanism when dealing with out-of-assembly resources?
I tried a few things in the x:Uid
such as ResourcesLibrary/Resources/ResourceTest
but with no luck.
But localization is not the only useful application for resources. In Windows applications, resources are also used for toolbar, menu, and status icons so that they don't need to be deployed separately with the application (which is not common for web applications).
The relationship between the string you use in x:Uid and the strings you use in a resources file is that the resource file strings are the x:Uid followed by a dot (.) and then by the name of a specific property of the element that's being localized. Consider this example:
Also, x:Name is governed by the XAML namescope concept, whereas uniqueness for x:Uid is controlled by the package resource index (PRI) system. For more info, see Resource Management System.
As a refresher, the advice in Microsoft Dev docs is to use a resource file that contains name value pairs to add string resources for a particular locale. The Uid of a control would be the base of the name. Next you would add a Uid to your component to reference it from the resource file:
I had the same problem for a long time. But after testing a little bit, I solved it by writing the whole Path of the Resources in the XAML Code.
Something like this:
<TextBlock x:Uid="/ResourcesLibrary/Resources/ResourceTest" />
Unfortunately this answer came very late, but may it can help other persons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With