Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind Strings from an .resw file with ReswFileCodeGenerator in XAML

I tried to localize my Windows Universal App with the Multilingual app toolkit. Because you can't bind strings directly from a .resw file in XAML, I used the ReswFileCodeGenerator tool. It works great in code behind, but in XAML I can't get this right.

In Windows Phone 8.0 I could use:

Text="{Binding Path=LocalizedResources.StringName, Source={StaticResource Strings}}"

Is there a similar way in Windows (Phone) 8.1 with the ReswFileGenerator tool?

like image 798
Matt126 Avatar asked Dec 12 '22 02:12

Matt126


2 Answers

I would still suggest you do it as Depechie already suggested: use x:Uid attribute.

If you need to get the localized string from code, just replace . in resource name with /. So, in XAML you'll write:

<TextBlock x:Uid="appString" />

In code you'll use:

var resourceLoader = new ResourceLoader();
var localizedText = resourceLoader.GetString("appString/Text");
like image 57
Damir Arh Avatar answered Feb 01 '23 07:02

Damir Arh


When doing resource translations in wp8.1 with .resw files, you need to use the x:Uid attribute on your xaml control!

Like <TextBlock x:Uid="FieldKey" />

Details are mentioned here...

like image 32
Depechie Avatar answered Feb 01 '23 08:02

Depechie