Visual Studio 2015 XAML 资源字典错误 [英] Visual Studio 2015 XAML Resource Dictionary Error

查看:108
本文介绍了Visual Studio 2015 XAML 资源字典错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PART 1(已解决)

以下 XAML 在 Visual Studio 2013(高级版,更新 5)中运行良好:

The following XAML works fine in Visual Studio 2013 (Premium, Update 5):

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

但是,在 Visual Studio 2015 (Enterprise) 中使用同一个项目时,它会抱怨以下错误:

However, when working with the same project in Visual Studio 2015 (Enterprise), it complains with the following error:

异常:查找资源字典时出错资源/字典/Main.xaml".

Exception: An error occurred while finding the resource dictionary "Resources/Dictionaries/Main.xaml".

另一个主题涉及 Visual 的类似错误Studio 2012,显然已通过为 VS2012 安装 Update 1 解决.

A different topic concerns a similar error with Visual Studio 2012, and was apparently resolved by installing Update 1 for VS2012.

第 2 部分

使用包 URI 使 Visual Studio 2015 高兴,但不幸的是它仍然没有应用继承的样式.有趣的是,在 Visual Studio 2013 设计器中,样式被正确应用,但在 Visual Studio 2015 中没有,在应用程序运行时也没有!

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!

有什么想法吗?

第 2 部分:更新

另一个(次要问题)使主要问题令人困惑的是主窗口的静态资源仅在处理主窗口定义后才加载".这意味着默认样式(特别是窗口样式)必须放置在 app.xaml 中,以便在加载主窗口时定义它们(否则它们将不会在设计器中应用,或者在应用程序中运行).

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

推荐答案

尝试以下操作:

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

这篇关于Visual Studio 2015 XAML 资源字典错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆