我对CustomResources做了很好的体验。
就在从CustomXamlResourceLoader继承你的UI项目的任何地方创建一个新的类,并实现以下方法:
protected override object GetResource(string resourceId, string objectType, string propertyName, string propertyType)
{
var parts = resourceId.Split('|');
if (parts.Length != 2)
throw new ArgumentException();
return ResourceLoader.GetForViewIndependentUse(parts[0]).GetString(split[1]);
}
然后创建资源的文件,我用他们的名字像我的页面,即“MainPage.resw”。
就是这样,现在你可以开始使用你的资源从XAML:
Text="{CustomResource MainPage|MyResourceKey}"
当然,分隔符可以做你想做的,它不局限于任何管道。只要确保你在你的ResourceLoader和你的XAML中使用相同的分隔符。
您不会在Designer中看到预览,但最大的好处是您可以拆分资源文件,而不必将所有内容合并到一起。
有关更多信息,请参阅https://msdn.microsoft.com/en-us/windows/uwp/xaml-platform/customresource-markup-extension。
您可以使用'x:Uid'或通过使用* ResourceLoader * - [在此帖子中的小示例](http://stackoverflow.com/a/24258472/2681948)创建类似于* LocalizedStrings *的内容。 – Romasz