gpt4 book ai didi

c# - 使用 XAML 中的 ReswFileCodeGenerator 从 .resw 文件绑定(bind)字符串

转载 作者:太空狗 更新时间:2023-10-30 00:07:13 24 4
gpt4 key购买 nike

我尝试使用多语言应用程序工具包本地化我的 Windows 通用应用程序。因为您不能直接从 XAML 中的 .resw 文件绑定(bind)字符串,所以我使用了 ReswFileCodeGenerator 工具。它在代码隐藏中运行良好,但在 XAML 中我做不到这一点。

在 Windows Phone 8.0 中我可以使用:

Text="{Binding Path=LocalizedResources.StringName, Source={StaticResource Strings}}"

在Windows (Phone) 8.1 中是否有类似的方式使用ReswFileGenerator 工具?

最佳答案

我仍然建议您按照 Depechie 的建议进行操作:使用 x:Uid 属性。

如果需要从代码中获取本地化字符串,只需将资源名称中的.替换为/即可。因此,在 XAML 中,您将编写:

<TextBlock x:Uid="appString" />

在您将使用的代码中:

var resourceLoader = new ResourceLoader();
var localizedText = resourceLoader.GetString("appString/Text");

关于c# - 使用 XAML 中的 ReswFileCodeGenerator 从 .resw 文件绑定(bind)字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27716103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com