Converter is the best way to do it. Check out my answer here for a quick explanation. I've copied the Converter I define there below.
ResourceController
is a simple Controller which gets a reference to a ResourceLoader
and retrieves values via a method GetString(string resourceId)
.
public class ResourceTranslationConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
var valString = value as string;
// If what is being converted is a string, return the resource translation
// Else return something else, such as the object itself
return valString == null ? value : ResourceController.GetString(valString);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
Binding then works like:
<TextBlock Text="{Binding LanguageResourceName, Converter={StaticResource ResourceTranslationConverter}}" />
Make sure you've defined an accessible ResourceTranslationConverter
. Possibly in the Page.Resources
or even in your App.xaml
(since you should only need one static reference).
Hope this helps and happy coding!