从单独的项目中加载 Blend 的内容图像

发布于 2024-08-29 10:04:50 字数 1319 浏览 3 评论 0原文

我有一个包含 5 个项目的 VS2010 解决方案。其中两个项目称为:

MyResources 应用程序

应用程序项目包含应用程序运行的所有视图和视图模型,资源项目包含用于主题和换肤的所有图像、资源字典等。

我在资源中设置图像的方式,将其构建操作设置为“内容”,并将“复制”设置为“始终复制”。在我的应用程序项目中,我使用包 URI 引用这些文件。示例:

"pack://siteoforigin:,,,/Themes/DefaultTheme/BackgroundImage.png"

这对我来说效果很好。由于我使用的是 siteoforigin://,因此主题文件夹及其所有子文件夹都已正确复制到正确的文件夹中。

然而,这破坏了可混合性。当我在 Blend 4 中加载项目时,出现错误。

如果我使用 siteoforigin,Blend 会尝试从 Blend.exe 的执行文件夹加载图像(在本例中为 C:\Program Files\Microsoft Expression\Blend 4 Beta\Themes\Default_Theme\BackgroundImage.png")

如果我更改将 URI 打包为以下内容:

pack://application:,,,/IQ.IQKiosk.Resources;component/Themes/DefaultTheme/BackgroundImage.png

它尝试在“themes/default_theme”中查找图像/backgroundimage.png"

如果我​​尝试:

/MyResources;component/Themes/DefaultTheme/BackgroundImage.png

它会尝试在“C:\MyResources;component\Themes\DefaultTheme\BackgroundImage.png”中查找图像。 png"

如果我​​尝试:

/Themes/DefaultTheme/BackgroundImage.png

它会尝试在“C:\Themes\DefaultTheme\BackgroundImage.png”中查找图像。

所以现在我被卡住了。我我不确定如何引用我的图像而不必将它们嵌入到资源项目中,并且我无法对目录进行硬编码,因为我的其他同事也将该项目放在不同的文件夹中,

我试图想出一种方法来获取。将正确的 URI 指向文件的正确位置(相对于 .sln 文件会很棒),或者将文件复制到 Blend 编译和执行项目的位置。唉,我无法弄清楚如何。

有谁知道加载这些图像的正确方法?

I have a VS2010 solution with 5 projects. Two of these projects are called:

MyResources
Application

The Application project contains all of the views and viewmodels for the application to run, and the Resources project contains all the images, resource dictionaries, etc for theming and skinning.

The way I have images set up in Resources, I have their build action set to Content, and Copy set to Copy Always. In my Application project, I reference these files using a pack URI. Example:

"pack://siteoforigin:,,,/Themes/DefaultTheme/BackgroundImage.png"

This works fine for me. The themes folder and all its subfolders are properly copied to the proper folder since I'm using siteoforigin://.

However, this breaks Blendability. When I load the project in Blend 4, I get errors.

If I use siteoforigin, Blend tries to load the images from the executing folder of blend.exe (In this case, C:\Program Files\Microsoft Expression\Blend 4 Beta\Themes\Default_Theme\BackgroundImage.png")

If I change the pack URI to the following:

pack://application:,,,/IQ.IQKiosk.Resources;component/Themes/DefaultTheme/BackgroundImage.png

It tries to look for the image in "themes/default_theme/backgroundimage.png"

If I try:

/MyResources;component/Themes/DefaultTheme/BackgroundImage.png

It tries to look for the image in "C:\MyResources;component\Themes\DefaultTheme\BackgroundImage.png"

If I try:

/Themes/DefaultTheme/BackgroundImage.png

It tries to look for the image in "C:\Themes\DefaultTheme\BackgroundImage.png".

So now I'm stuck. I'm not sure how to reference my images without having to embed them into the resource project, and I can't hard code the directory because my other coworkers have the project in different folders as well.

I tried to think of a way to get the proper URI to the proper locations of the files (relative to the .sln file would be awesome) or have the files get copied over to where blend compiles and executes the project. Alas, I am unable to figure out how.

Does anyone know the proper way to get these images to load?

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

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

发布评论

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

评论(1

蔚蓝源自深海 2024-09-05 10:04:50

我想通了。我没有使用包 URI,而是使用了

new Uri(Environment.CurrentDirectory + "\\Themes\\DefaultTheme\\BackgroundImage.png")

并且它找到了正确的文件夹,因为 Evironment.CurrentDirectory 给出了我的主题被复制到正确的 bin 文件夹中。

好哇!

I figured it out. Instead of using a pack URI, I just used

new Uri(Environment.CurrentDirectory + "\\Themes\\DefaultTheme\\BackgroundImage.png")

and it found the proper folder, since Evironment.CurrentDirectory gave me the proper bin folder where my themes were copied to.

Huzzah!

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