我對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