Question

I have been trying to come up with a better localization approach than LocBaml (wich sucks). And I though I could use something like {DynamicResource {x:Static LocalizableTexts.OpenTextKey}} (dynamicresource because my language could change at runtime). The only question is? How do I correctly create LocalizableTexts.OpenTextKey ? Is there a tutorial out there that can teach me how to create custom RessourceKeys and how to update them at runtime?

I am living in the MVVM world by the way ...

Was it helpful?

Solution

I think your after component resource keys.

Start by defining your resource in a XAML resource dictionary, something like:

<local:OpenText x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:LocalizableTexts}, ResourceId=OpenText}" />

Then create a static accessor class:

public static class LocalizableTexts
{
     public static ComponentResourceKey OpenTextKey
     {
        get { return new ComponentResourceKey(typeof(LocalizableTexts), "OpenText"); }
     }
}

Finally be sure you indicate the xml namespace when you use a static binding:

{DynamicResource {x:Static local:LocalizableTexts.OpenTextKey}} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top