Conditional loading of resource strings using x:Uid attribute RRS feed

  • Question

  • My Windows 8.1 Store app is already localized using standard approach with Resources.resw files and switching between languages works fine. What I would like now in my app is to use two sets of string resources for each of the languages supported, eg. "formal" and "informal". To accomplish this I have placed besides default (formal) Resources.resw a file named ResourcesInformal.resw with altered strings. When my app is started with a setting "informal" I can load strings from the informal resource file in code-behind (programmatically) just fine, because I can specify the resource name when instantiating ResourceLoader (regardless to the language).

    The problem is in the XAML files where I need to use one of the following lines based on the app setting:

    <TextBlock x:Uid="\ResourcesInformal\GreetingText"..>
    <TextBlock x:Uid="Greetingtext">

    Is there a way I could pre-pend this "\ResourcesInformal\" text to the x:Uid attribute when needed or use some kind of converter to accomplish this in the runtime? (I don't want to move assignment of the text to code-behind or double the controls and handle this with Visibility.)


    Wednesday, November 19, 2014 2:17 PM


  • You cannot change an x:Uid directives programmatically at runtime. You will need to somehow replace the default resource loader, so that it gets the resources from ResourcesInformal.resw instead of Resources.resw, to be able to use the x:Uid directives approach here. I am afraid there is no easy way do this that I know of though so you should probably replace the x:Uid directives with bindings to some properties of a class where you can dynamically change the ResourceLoader that is used to load the resources. Please refer to the ResW File Code Generator in CodePlex: https://reswcodegen.codeplex.com/. The generated ResourceClass with the Test1, Test2, ... properties should give you the idea.
    Wednesday, November 19, 2014 7:51 PM