资源本地化:使用x:Uid引用另一个程序集的资源 [英] Resource localization: use of x:Uid referring to another assembly's resource

查看:80
本文介绍了资源本地化:使用x:Uid引用另一个程序集的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个win8应用程序,并将使用内置的资源管理系统:XAML代码中的resw文件和x:Uid标记.

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.

所以我创建一个像这样的TextBox:

So I create let's say a TextBox like that:

<TextBlock Style="{StaticResource HeaderTextStyle}" x:Uid="ResourceTest"/>

我使用ResourceTest.Text条目在程序集中创建了相应的资源文件,并且工作正常:在运行时显示正确的文本.

I create the corresponding resource file in my assembly with a ResourceTest.Text entry and it works fine: proper text is displayed at runtime.

现在,我想将所有resx文件移动到另一个C#库中以实现可维护性.因此,我将资源文件放在一个全新的项目中,并从主程序集中引用了这个新程序集.

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).

但是,如果我使用以下代码从侧面程序集(称为ResourcesLibrary)内部以编程方式检索资源值,则可以正确获取字符串:

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);
}

在处理组装外资源时如何启用x:Uid机制?

How do I enable the x:Uid mechanism when dealing with out-of-assembly resources?

我尝试了x:Uid中的一些操作,例如ResourcesLibrary/Resources/ResourceTest,但是没有运气.

I tried a few things in the x:Uid such as ResourcesLibrary/Resources/ResourceTest but with no luck.

推荐答案

我很长一段时间都遇到过同样的问题.但是经过一点测试之后,我通过在XAML代码中编写资源的整个路径来解决了这个问题.

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.

类似这样的东西:

<TextBlock x:Uid="/ResourcesLibrary/Resources/ResourceTest" />

不幸的是,这个答案来得很晚,但是可能可以帮助其他人.

Unfortunately this answer came very late, but may it can help other persons.

这篇关于资源本地化:使用x:Uid引用另一个程序集的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆