Last active
October 26, 2015 13:30
-
-
Save konradbartecki/3e315c3b24f5eb1dd413 to your computer and use it in GitHub Desktop.
Binding from .resw files example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocalizationHelper | |
{ | |
public LocalizationHelper() | |
{ | |
} | |
public static string GetString(string resourcefile, string key) | |
{ | |
var resourceLoader = ResourceLoader.GetForViewIndependentUse(resourcefile); | |
return resourceLoader.GetString(key); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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}}"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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