WPF 中的包表示法

发布于 2024-08-03 05:14:03 字数 659 浏览 4 评论 0原文

我有一个关于包符号的问题。

我正在尝试从另一个资源程序集访问 XAML 页面中的 png 图像文件。

假设资源程序集(位于我的 xaml 文件所在的本地程序集之外)是 ResourceAssembly.Common.Resources 我的图像位于 ResourceAssembly.Common.Resources/Images/image.png 中。

我的包符号如下所示:

<Image Source="pack://application:,,,/ResourceAssembly.Common.Resources;component/Images/image.png" />

现在,我已经检查了一遍,检查了 MSDN 库,检查了博客和所有内容,据我所知,这是正确的。我不确定为什么我的图像没有显示或者问题是什么。

我收到的错误是: “错误 633 无法加载文件或程序集“ResourceAssembly.Common.Resources,Culture=neutral”或其依赖项之一。系统找不到指定的文件。

我想我错过了一些简单的 内容关键字或一些简单的语法错误,或者类似的问题始终是我的问题,但任何帮助都是非常宝贵的。

谢谢! 阿努杰

I have a question about pack notation.

I'm trying to access a png image file within a XAML page from another resource assembly.

Let's say the Resource Assembly (which is outside of the local assembly that my xaml file is in), is ResourceAssembly.Common.Resources
and that my image is in ResourceAssembly.Common.Resources/Images/image.png.

My pack notation looks as follows:

<Image Source="pack://application:,,,/ResourceAssembly.Common.Resources;component/Images/image.png" />

Now, I've checked this and checked it again, checked MSDN libraries, checked blogs and everything, and as far as I know, that is correct. I'm not sure why my image isn't displaying or what the problem is.

The error I'm getting is:
"Error 633 Could not load file or assembly 'ResourceAssembly.Common.Resources, Culture=neutral' or one of its dependencies. The system cannot find the file specified."

I imagine I'm missing some simple keyword or some simple syntax error, or something along those lines as that always my problem, but any assistance would be invaluable.

Thanks!
Anuj

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

滿滿的愛 2024-08-10 05:14:03

当我开始使用包表示法时,我遇到了类似的问题,但我现在不记得具体问题是什么。您的包符号看起来与我的相同,因此我将验证每个部分并确保其正确:

  1. 您的资源程序集的 AssemblyInfo.cs 是否准确包含:[ assembly: AssemblyTitle("ResourceAssembly.Common .资源")]? (只需确保 ResourceAssembly.Common.Resources 是实际的程序集名称,而不是项目名称或命名空间。)

  2. 客户端项目是否引用 ResourceAssembly.Common。资源 程序集或项目?

  3. GAC 中是否有可能安装 ResourceAssembly.Common.Resources 的副本? (如果它在本地和 GAC 中存在,则可能会导致短名称冲突。)

  4. “Images”文件夹是 ResourceAssembly.Common.Resources 项目的直接子级吗? (听起来确实如此,但只是确定一下。)

  5. image.png 的 Build Action 属性是否设置为 Resource? (默认情况下应该如此,但你永远不知道。)

  6. ResourceAssembly.Common.Resources 是否引用了客户端项目中未包含的任何程序集? (XAML 中的 Pack URI 在编译时 IIRC 时不会解析,这意味着传递依赖项不会带入项目中。)

如果它不是其中之一,那么它超出了我的范围。 :)

I had a similar problem when I started using pack notation, but I can't remember now what the specific problem was. Your pack notation looks identical to what I'm, so I would verify each part and make sure it's correct:

  1. Does the AssemblyInfo.cs for your resource assembly contain exactly: [assembly: AssemblyTitle("ResourceAssembly.Common.Resources")]? (Just making sure that ResourceAssembly.Common.Resources is the actual assembly name and not the project name or a namespace.)

  2. Does the client project have a reference to ResourceAssembly.Common.Resources assembly or project?

  3. Is there any chance a copy of ResourceAssembly.Common.Resources is installed in the GAC? (If it exists locally and in the GAC, it could cause a short name conflict.)

  4. Is the "Images" folder a direct child of the ResourceAssembly.Common.Resources project? (Sounds like it is, but just making sure.)

  5. Is the Build Action property for image.png set to Resource? (It should be by default, but you never know.)

  6. Does ResourceAssembly.Common.Resources reference any assemblies that are not included in your client project? (Pack URIs in XAML are not resolved at compile time IIRC, which means transitive dependencies will not be brought into the project.)

If it's not one of those things then it's beyond me. :)

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