Visual Studio 2015 XAML Resource Dictionary Error

女生的网名这么多〃 提交于 2019-12-11 03:54:33

问题


PART 1 (solved)

The following XAML works fine in Visual Studio 2013 (Premium, Update 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:

Exception: An error occurred while finding the resource dictionary "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.

PART 2

Using the pack URI makes Visual Studio 2015 happy, but unfortunately it is still not applying inhertied styles. Interestingly, in Visual Studio 2013 designer the style is applied correctly, but not in Visual Studio 2015, and also not when the application runs!

Any Ideas?

PART 2 : UPDATE

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


回答1:


Try the following:

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


来源:https://stackoverflow.com/questions/31570132/visual-studio-2015-xaml-resource-dictionary-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!