当 ResourceDictionary 位于子文件夹中时,VS2010 设计器无法工作

发布于 2024-10-31 00:54:42 字数 732 浏览 0 评论 0原文

我有一个项目,其中包含应用程序的入口点和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漫漫岁月 2024-11-07 00:54:42

您的代码应如下所示,以便使用应用程序根目录之外的子目录:

<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="pack://siteoforigin:,,,../Styles/Style.xaml"></ResourceDictionary>
    </Application.Resources>
</Application>

Your code should look this way in order to use subdirectories out of your application root directory:

<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="pack://siteoforigin:,,,../Styles/Style.xaml"></ResourceDictionary>
    </Application.Resources>
</Application>
沒落の蓅哖 2024-11-07 00:54:42

这可能与“Source”属性的格式有关。
格式必须是 Pack URI,如“pack://siteoforigin:,,,/SiteOfOriginFile.xaml”,

请查看 MSDN 中的这些文档:

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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文