简体   繁体   中英

Build action Page or Resource

I have several ResourceDictionaries in my application to make it localizable. These files are named smelling like Language_en.xaml , Language_nl.xaml , etc. An example of such a file is given below.

<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".

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.

Page (wpf only): Used to compile a xaml file into baml. The baml is then embedded with the same technique as Resource (ie available as `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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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