Resource localization: use of x:Uid referring to another assembly's resource

[亡魂溺海] 提交于 2019-12-03 12:23:29

问题


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.


回答1:


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.




回答2:


As per my understanding you can't use x:Uid if the resources are maintained in a .resx file.

if you use .resw files you can access the strings whatever the assembly they are residing in.

they can be accessed as you mentioned in your question like this "ResourcesLibrary/Resources/ResourceTest"



来源:https://stackoverflow.com/questions/14929590/resource-localization-use-of-xuid-referring-to-another-assemblys-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!