如何在我的 XAML 中使用来自另一个项目的图像? [英] How do I use an image from another project in my XAML?

查看:30
本文介绍了如何在我的 XAML 中使用来自另一个项目的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个包含多个项目的解决方案(Windows Phone 应用程序);其中一个项目是品牌"——它包含一些特定的代码和图像,其想法是这个项目可以换成不同的品牌.

I am building a solution (Windows Phone app) with multiple projects; one of those projects is for "branding" - it contains some specific code as well as images, and the idea is that this project can be swapped out for different branding.

我的应用页面在主项目中,我想在主应用的 UI 中显示存储在第二个项目中的图像.

My app pages are in the main project, and I want to display images stored in the 2nd project in the main app's UI.

我的项目可以编译并具有正确的依赖项等.但是我的图像没有显示在 UI 中.我不确定我应该如何引用它们.

My projects compile and have the correct dependencies, etc. But my images don't show in the UI. I'm not sure how I'm supposed to reference them.

这是当图像存储在主项目中时图像在 XAML 中的编码方式 - 这非常有效:

This is how the images are coded in the XAML when the images are stored in the main project - this works perfectly:

<Image Source="/MainProject;component/ThisTeam/Trophy.png"/>

但是,我想将图像存储在我的辅助项目中,但在我的主项目中使用它们,因此以下不起作用(XAML 来自 MainProject):

However, I want to store the images in my secondary project but use them in my primary project, so the following DOESN'T work (the XAML is from MainProject):

<Image Source="/SecondaryProject;component/Images/Soccer.png"/>

图像上的构建类型设置为内容,但是我尝试了资源和其他设置.由于图像在存储在主项目中时有效,我认为这不是问题所在.

Build type on the images is set to content, however I have tried Resources and other settings. Since the images work when stored in the main project I assume it's something other than that that is the issue.

我的主项目使用辅助项目中的代码,因此我对该项目的引用可以正常工作.

My main project uses code from the secondary project, so my reference to that project works correctly.

我这样做是错误的吗?甚至有可能实现我想要的目标吗?

Am I doing this the wrong way? Is it even possible to achieve what I'm trying to?

推荐答案

好的,我已经解决了这个问题.

OK, I have resolved this issue.

在我的摆弄中,我删除了对我的一个项目的引用 - 但由于某些类具有匹配的名称,该解决方案仍在编译和运行!

In my fiddling I had removed the reference to one of my projects - but due to some classes with matching names the solution was still compiling and running!

此外,正如 Alastair 所指出的,我需要将图像更改为资源内容类型(我不确定为什么,因为它们在与 XAML 代码位于同一项目中时使用内容类型).

And also, as Alastair noted, I needed to change the images to a Resource content type (I'm not sure why, as they work with the Content type when in the same project as the XAML code).

所以我在问题中发布的 XAML 是正确的 - 但前提是项目被正确引用并且内容类型设置为 Resource.

So the XAML I posted in my question was correct - but only if the projects are referenced correctly and the content type is set to Resource.

这篇关于如何在我的 XAML 中使用来自另一个项目的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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