在设计时包uri是有效的,但不是在运行时? [英] At design time pack uri is valid, but not at runtime?

查看:170
本文介绍了在设计时包uri是有效的,但不是在运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Button的内容设置为图像。它看起来像这样:

I'm setting a Button's content to an Image. It looks something like this:

<Button>
   <Image Source="pack://application:,,,/NavigationImages/nav_up_left.png" />
</Button>

在我的项目中,我有一个名为NavigationImages的子文件夹,在该文件夹中是图像文件nav_up_left.png。

In my project I have a subfolder named NavigationImages and within that folder is the image file nav_up_left.png.

当我查看Designer时,图像出现,但是在运行时我遇到IOException错误,说它找不到资源。

When I view the Designer the image appears, however during runtime I get an IOException error saying it cannot locate the resource.

Build Action设置为Resource。

The Build Action is set to Resource.

实际上,这在一个项目中运作良好。但是,当我将它复制到另一个项目时,它失败了。这似乎是一个非常简单的问题,但我发现自己很难过,准备开始拔头发了。 @ _ @

Actually, this worked fine in one project. But when I copied it over the another project it fails. This seems like an incredibly simple problem, but I find myself stumped and ready to start pulling out hair. @_@

您的意见和建议将不胜感激!

Your thoughts and suggestions will be much appreciated!

推荐答案

<是的,我明白了......有点儿。

Whelp, I figured it out...kinda.

我将xaml代码从输出类型为Windows Application的一个项目复制到另一个输出类型为Class Library的项目。

I copied that xaml code from one project where the output type is Windows Application, to another project where the output type is Class Library.

我当时没有想到它,但显然当输出类型是类库时,包URI需要更改。

I didn't think of it at the time, but apparently when the output type is a Class Library the pack URI needs to change.

因此,而不是pack:// application:,,, / NavigationImages / nav_up_left.png我将其更改为/ ProjectName; component / NavigationImages / nav_up_left.png现在它的工作正常。

So instead of "pack://application:,,,/NavigationImages/nav_up_left.png" I changed it to "/ProjectName;component/NavigationImages/nav_up_left.png" and now it's working just fine.

我不是100%明白为什么这是有效的,而不是前者。我已经阅读了有关包URI的 MSDN文档在WPF中但也许我误解了一些东西。

I'm not 100% clear why this is works and not the former. I've read through the MSDN documentation on pack URIs in WPF but perhaps I misinterpreted something.

如果有人能给我一个很好的解释,为什么我之前的东西在输出类型为Class Library的项目中不起作用,我将不加考虑这个答案。

I'll leave this answer unchecked in the event someone can give me a good explanation why what I previously had doesn't work in a project with output type Class Library.

我可能错过了一些非常简单的事情。 @ _ @

I'm probably missing something really simple. @_@

这篇关于在设计时包uri是有效的,但不是在运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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