Skip to content

Instantly share code, notes, and snippets.

@konradbartecki
Last active October 26, 2015 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konradbartecki/3e315c3b24f5eb1dd413 to your computer and use it in GitHub Desktop.
Save konradbartecki/3e315c3b24f5eb1dd413 to your computer and use it in GitHub Desktop.
Binding from .resw files example
<Application
(...)
<!--I have placed my resource string conventer in "Converters" folder-->
xmlns:converters="using:MyWindowsPhoneApp.Converters">
<Application.Resources>
(...)
<converters:ResourceStringConventer x:Key="ResString"/>
(...)
</Application.Resources>
</Application>
public class LocalizationHelper
{
public LocalizationHelper()
{
}
public static string GetString(string resourcefile, string key)
{
var resourceLoader = ResourceLoader.GetForViewIndependentUse(resourcefile);
return resourceLoader.GetString(key);
}
}
//For resource in file Page.Login.resw and string ID "NotUserYet"
<TextBlock Text="{Binding ConverterParameter=Page.Login/NotUserYet, Converter={StaticResource ResString}, Mode=OneWay, Source={StaticResource ResString}}"/>
public class ResourceStringConventer : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (parameter == null || !(parameter is string))
{
return "Parameter is null or is not string";
}
var parameters = (parameter as string).Split('/');
string text = LocalizationHelper.GetString(parameters[0], parameters[1]);
return text;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment