我的应用程序中有多个 ResourceDictionaries
以使其可本地化。这些文件的名称有点像 Language_en.xaml、Language_nl.xaml 等。下面给出了此类文件的示例。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<!-- DO NOT LOCALIZE -->
<system:String x:Key="Language">English</system:String>
<FlowDirection x:Key="FlowDirection">LeftToRight</FlowDirection>
<!-- DO LOCALIZE -->
<system:String x:Key="Title">English Title External</system:String>
</ResourceDictionary>
为了在应用程序运行时加载这些文件,我创建了如下路径:
_appResDicSource = Path.Combine("\\" + _projectName + ";component", _languagesDirectoryName,
_fileBaseName + "_" + language + ".xaml");
_clsLibResDicSource = "\\MyDLL;component\\Languages\\Language_" + language + ".xaml";
以上内容适用于构建操作 Resource
和 Page
,其中 CtOD 设置为“Do not copy”,自定义工具设置为“MSBuild:Compile”。
来自 this link我了解了下面的引述,但对我的项目来说最好的是什么?
Resource (wpf only): embeds the file in a shared (by all files in the assembly with similar setting) assembly manifest resource named AppName.g.resources.
Page (wpf only): Used to compile a xaml file into baml. The baml is then embedded with the same technique as Resource (i.e. available as `AppName.g.resources)
最佳答案
当您在 Visual Studio (2017) 中添加 ResourceDictionary 时,Build Action: Page 是默认设置的,因此这是一个有利于 Page 的提示。我在下面的链接中找到了更多相关信息:
关于c# - 构建操作页面或资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29887952/