当 ResourceDictionary 位于子文件夹中时,VS2010 设计器无法工作
我有一个项目,其中包含应用程序的入口点和 ResourceDictionary。这些文件第一次位于项目的根目录下。这时我就可以在其他项目的xaml文件的设计器中看到该样式修改的所有组件(例如按钮)。
现在,我有这样的子文件夹:src/launcher,其中包含我的入口点和src/styles,其中包含我的ResourceDictionary。但现在,这些组件在 VS2010 的设计器中没有样式。程序编译并运行良好,但设计器不起作用。我不断收到“找不到资源...”错误。 我的主 xaml 文件的代码是:
<Application x:Class="MANAGER.Program"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">
<Application.Resources>
<ResourceDictionary Source="../Styles/Style.xaml"></ResourceDictionary>
</Application.Resources>
</Application>
为什么设计器不起作用?
I have a project which contains the entry point of my application and a ResourceDictionary. In a first time, these files were located at the root of the project. At this time, I could see all the components (button for exemple) modified by the style in the designer of xaml files in other projects.
Now, I have subfolders like this : src/launcher which contains my entry point and src/styles which contains my ResourceDictionary. But now, the components are not styled in the designer of VS2010. The program compiles and works well, but the designer doesn't work. I get the "Cannot find the resource ..." error constantly.
The code of my main xaml file is :
<Application x:Class="MANAGER.Program"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">
<Application.Resources>
<ResourceDictionary Source="../Styles/Style.xaml"></ResourceDictionary>
</Application.Resources>
</Application>
Why the designer doesn't work ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码应如下所示,以便使用应用程序根目录之外的子目录:
Your code should look this way in order to use subdirectories out of your application root directory:
这可能与“Source”属性的格式有关。
格式必须是 Pack URI,如“pack://siteoforigin:,,,/SiteOfOriginFile.xaml”,
请查看 MSDN 中的这些文档:
ResourceDictionary.Source 属性
WPF 中的数据包 URI
It might have something to do with the format of the "Source" attribute.
The format needs to be a Pack URI like "pack://siteoforigin:,,,/SiteOfOriginFile.xaml"
Have a look at these documentations in MSDN:
ResourceDictionary.Source Property
Packet URIs in WPF