设计时的 UWP 资源字符串 (.resw) [英] UWP resource strings at design time (.resw)

查看:28
本文介绍了设计时的 UWP 资源字符串 (.resw)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照

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

解决方案

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.

这篇关于设计时的 UWP 资源字符串 (.resw)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆