【发布时间】:2023-03-26 06:41:01
【问题描述】:
来自.resw 的字符串资源,用于 Windows 8 中的数据绑定。
在 Windows Phone 中我使用如下:
- 创建
AppStrings.resx并将所有字符串放在上面。 - 创建类
StringResources,其字段返回AppStrings.resx的实例。 - 将
StringResources添加到ApplicationResource。
StringResources.cs
public class StringResources
{
private static AppStrings _resources;
public static AppStrings LocalizedResources
{
get { return _resources ?? (_resources = new AppStrings()); }
}
}
在 App.xaml 中
<Application.Resources>
<ResourceDictionary>
<res:StringResources x:Key="Strings"/>
</ResourceDictionary>
</Application.Resources>
使用我来自 xaml 的资源。
Text="{Binding Path=LocalizedResources.StringName, Source={StaticResource Strings}}"
一切都很好,但我不能在 Windows 8 中做到这一点。
我正在搜索与 Windows 8 上的字符串资源类似的使用方式 DataBinding。
注意:
我检查了MSDN Sample,但找不到我需要的。
我也检查了ResW File Code Generator,这是可行的方法,但太牵强了.
【问题讨论】:
标签: xaml data-binding windows-runtime