Application.GetResourceStream呼吁内容资源仍返回null [英] Application.GetResourceStream called on a Content Resource still return null
问题描述
下面是VS2010项目(Windows phone)系统的任务相关的部分结构:
Here is the task-related part of the VS2010 project (Windows Phone) structure:
在code正在从DummyMediaLibProvider.cs执行:
The code is being executed from DummyMediaLibProvider.cs:
public class DummyMediaLibProvider: IMediaLibProvider
{
...
StreamResourceInfo albumArtPlaceholder =
Application.GetResourceStream(
new Uri("../Images/artwork.placeholder.png", UriKind.Relative));
artwork.placeholder.png
的生成操作的设置为内容的。
不过,每当我跑了code, Application.GetResourceStream
返回null。
Still, whenever I run the code, Application.GetResourceStream
returns null.
这可能是对资源的原因不被读取到内存?
What may be the reason for the resource not being read to memory?
我试图删除项目的OBJ目录下,并清理和重建,但至今没有任何帮助。
I have attempted to delete obj directory of the project, did Clean and Rebuild, but so far nothing helped.
更新:
如果我申请生成操作:资源来artwork.placeholder.png,我可以得到的资源流ok了,虽然
If I apply Build Action: Resource to artwork.placeholder.png, I can get the resource stream ok though.
P.S。这不是<一个重复href="http://stackoverflow.com/questions/5918072/application-getcontentstream-returns-null-for-content-uri">Application.GetContentStream上次有扩展名(particurarly的.xml)的相关问题返回内容乌里空。
推荐答案
提供的 Application.GetResourceStream
的路径是不相类的地位,但相对于应用程序包。
The path supplied Application.GetResourceStream
isn't relative to the position of the class, but relative to the application package.
StreamResourceInfo albumArtPlaceholder =
Application.GetResourceStream(
new Uri("Images/artwork.placeholder.png", UriKind.Relative));
将是正确的路径。您也可以尝试采用了全包的URI。 (请参阅MSDN )
最后,资源
将是正确的生成操作
这一点。
And finally, Resource
would be the correct Build Action
for this.
这篇关于Application.GetResourceStream呼吁内容资源仍返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!