简体   繁体   English

Visual Studio 2015 XAML资源字典错误

[英]Visual Studio 2015 XAML Resource Dictionary Error

PART 1 (solved) 第1部分 (已解决)

The following XAML works fine in Visual Studio 2013 (Premium, Update 5): 以下XAML在Visual Studio 2013(高级版,更新5)中可以正常工作:

<Window.Resources>
  <ResourceDictionary Source="Resources/Dictionaries/Main.xaml" />
</Window.Resources>

However, when working with the same project in Visual Studio 2015 (Enterprise), it complains with the following error: 但是,在Visual Studio 2015(Enterprise)中使用同一项目时,它会报告以下错误:

Exception: An error occurred while finding the resource dictionary "Resources/Dictionaries/Main.xaml". 例外:查找资源字典“ Resources / Dictionaries / Main.xaml”时发生错误。

A different topic concerns a similar error with Visual Studio 2012, and was apparently resolved by installing Update 1 for VS2012. 另一个主题涉及Visual Studio 2012的类似错误,并且显然可以通过安装VS2012 Update 1来解决。

PART 2 第2部分

Using the pack URI makes Visual Studio 2015 happy, but unfortunately it is still not applying inhertied styles. 使用包URI使Visual Studio 2015感到高兴,但不幸的是,它仍未应用继承的样式。 Interestingly, in Visual Studio 2013 designer the style is applied correctly, but not in Visual Studio 2015, and also not when the application runs! 有趣的是,在Visual Studio 2013设计器中,样式已正确应用,但在Visual Studio 2015中未正确应用,并且在应用程序运行时也未正确应用样式!

Any Ideas? 有任何想法吗?

PART 2 : UPDATE 第2部分:更新

A further (side issue), that was confusing the main issue was "static resources for the main window are only loaded after the main window definition is processed". 另一个使主要问题感到困惑的(附带问题)是“仅在处理主窗口定义之后才加载主窗口的静态资源”。 This means that default styles (in specific, a window style) must be placed in app.xaml so that they are defined by the time the main window is loaded (otherwise they will not be applied in the designer, or in the application when it runs). 这意味着必须将默认样式(特别是窗口样式)放置在app.xaml中,以便在加载主窗口时定义它们(否则,它们将不会在设计器中或应用程序在应用时被应用)运行)。

请尝试以下操作:

<ResourceDictionary Source="pack://application:,,,/YourNamespace;component/Resources/Dictionaries/Main.xaml" />

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

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