c# - 构建操作页面或资源

标签 c# xaml

我的应用程序中有多个 ResourceDictionaries 以使其可本地化。这些文件的名称有点像 Language_en.xamlLanguage_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";

以上内容适用于构建操作 ResourcePage,其中 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 的提示。我在下面的链接中找到了更多相关信息:

https://learn.microsoft.com/en-us/dotnet/framework/wpf/app-development/wpf-application-resource-content-and-data-files

关于c# - 构建操作页面或资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29887952/

相关文章:

c# - 知道 Iqueryable 的元素数量

c# - 动态 LINQ 查询中 DateTime.AddMinutes() 的问题

wpf - WPF 中 DataGrid 的多级列标题

c# - 如何在 XAML 电话应用程序中禁用 scrollviewer 自动移动 scrollviewer

wpf - 如何通过 XAML 设置 WPF 超链接文本

c# - WCF 服务向客户端发送数据

c# - 将扩展方法中的事件和函数分配为参数

c# - 如何将 xaml 中的数据触发器绑定(bind)到代码定义的依赖属性?

c# - 可以在 XAML 中选择 AncestorType 的名称

c# - 如何使用 C# 应用程序查询 MS Access 数据库?