简体   繁体   English

构建行动页面或资源

[英]Build action Page or Resource

I have several ResourceDictionaries in my application to make it localizable. 我的应用程序中有几个ResourceDictionaries ,可以进行本地化。 These files are named smelling like Language_en.xaml , Language_nl.xaml , etc. An example of such a file is given below. 这些文件的名称类似于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>

To load these files when the application is running I create the paths like this: 要在应用程序运行时加载这些文件,我创建如下路径:

_appResDicSource = Path.Combine("\\" + _projectName + ";component", _languagesDirectoryName,
            _fileBaseName + "_" + language + ".xaml");
_clsLibResDicSource = "\\MyDLL;component\\Languages\\Language_" + language + ".xaml";

The above is working for both Build Actions Resource and Page with the CtOD set to "Do not copy" and Custom Tool set to "MSBuild:Compile". 以上内容适用于构建操作ResourcePage ,其中CtOD设置为“不复制”,自定义工具设置为“MSBuild:Compile”。

From this link I learned the quote below, but what is the best thing for my project? 这个链接我学到了下面的引用,但对我的项目来说最好的是什么?

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. 资源(仅限wpf):将文件嵌入共享(由具有类似设置的程序集中的所有文件)组装清单资源,名为AppName.g.resources。

Page (wpf only): Used to compile a xaml file into baml. Page(仅限wpf):用于将xaml文件编译为baml。 The baml is then embedded with the same technique as Resource (ie available as `AppName.g.resources) 然后使用与Resource相同的技术嵌入baml(即可用作'AppName.g.resources)

When you add a ResourceDictionary in Visual Studio (2017), Build Action: Page is set by default, so thats an hint favoring Page. 在Visual Studio(2017)中添加ResourceDictionary时,默认情况下会设置“构建操作:页面”,因此这是一个有利于Page的提示。 I found more related info in the link below: 我在下面的链接中找到了更多相关信息:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM