11

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Qortex
  • 7,087
  • 3
  • 42
  • 59
  • Have you found the solution since asking the question? I'm facing the same problem right now. – Martin Suchan May 22 '13 at 07:51
  • nope, I fell back to using the same assembly, didn't have time to investigate. – Qortex May 24 '13 at 20:44
  • 2
    Actually we've ended using this tool for generating code-behind class for resw resource file, works like a charm even when the resw is in another assembly: http://reswcodegen.codeplex.com/ – Martin Suchan May 26 '13 at 18:05

2 Answers2

16

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.

Donnie
  • 45,732
  • 10
  • 64
  • 86
Matt126
  • 997
  • 11
  • 25
0

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"

Suresh
  • 47
  • 2
  • 8