简体   繁体   English

WPF资源字典生成操作

[英]WPF Resource Dictionary Build Action

I have a ResourceDictionary in a xaml file called SylesResourceDictionary.xaml in a Class Library Project. 我在Class Library项目的名为SylesResourceDictionary.xaml的xaml文件中有一个ResourceDictionary This ResourceDictionary is used in different views by Merging. 通过合并,此ResourceDictionary在不同的视图中使用。

I'm new to ResourceDictionary and not sure if I'm doing it the right way. 我是ResourceDictionary新手,不确定是否以正确的方式进行操作。 Different article suggest different Build Action Like Page and Custom Tool Like XamlIntelliSenseFileGenerator 不同的文章建议不同的构建操作(如Page和自定义工具(如XamlIntelliSenseFileGenerator

  1. What should be the Build Action for this xaml file ? 此xaml文件的Build Action应该是什么? I have it set to Resource 我将其设置为资源

  2. What should be the Custom Tool ? 什么是Custom Tool I have it set to MSBuildCompile 我将其设置为MSBuildCompile

  3. Should I delete the xaml.cs file for this xaml file ? 我应该删除该xaml文件的xaml.cs文件吗?

  1. The Build Action of a ResourceDictionary should be set to Page . ResourceDictionary的构建操作应设置为Page
  2. XamlIntelliSenseFileGenerator . XamlIntelliSenseFileGenerator Only the XAML compiler knows how to compile the XAML file to BAML. 只有XAML编译器知道如何将XAML文件编译为BAML。
  3. Yes, unless you have any custom code defined in the code-behind file. 是的,除非您在代码隐藏文件中定义了任何自定义代码。 A ResourceDictionary may have a code-behind file but by default it's XAML only. ResourceDictionary可能有一个代码隐藏文件,但默认情况下仅是XAML。

You may also want to consider creating a project using either the WPF Custom Control Library template or the WPF User Control Libary template instead of using the Class Library template. 您可能还需要考虑使用WPF Custom Control Library模板或WPF User Control Libary模板而不是Class Library模板来创建项目。 This will make it easier working with WPF and XAML specific types in Visual Studio. 这将使在Visual Studio中使用WPF和XAML特定类型更加容易。 You will still be able to add any other types to the project as well. 您仍然可以将任何其他类型添加到项目中。

In general: 一般来说:

  1. Page
  2. XamlIntelliSenseFileGenerator XamlIntelliSenseFileGenerator
  3. No! 没有!

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

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