问题
I've created a .resw file by following the instructions at https://docs.microsoft.com/en-us/windows/uwp/globalizing/put-ui-strings-into-resources. While the localization works fine at runtime, no text is displayed at design time.
The only solution proposed so far seems to only work in windows 8.1 apps: Windows store app ResourceLoader at design time
回答1:
The New Method
of solution that you have mentioned also works in UWP. And it's more recommended to use Data Binding at design time.
The following class works like .resw file reader
. If you send the key parameter it will return the value for key.
public class LocalizedStrings
{
public string this[string key]
{
get
{
return ResourceLoader.GetForViewIndependentUse().GetString(key);
}
}
}
Before using binding, you need to instantiate the reader
in the App.xaml file.
<Application.Resources>
<ResourceDictionary>
<local:LocalizedStrings x:Key="Localized"/>
</ResourceDictionary>
</Application.Resources>
Resources.resw
<data name="Title" xml:space="preserve">
<value>ResTitleTest</value>
</data>
Usage
<TextBlock Text="{Binding Source={StaticResource Localized}, Path=[Title]}" />
Note: Only after build, the content of Textblock
will display where in the designer.
来源:https://stackoverflow.com/questions/45723217/uwp-resource-strings-at-design-time-resw