UWP resource strings at design time (.resw)

会有一股神秘感。 提交于 2019-12-23 02:18:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!