Silverlight (WP7) 加载资源 [英] Silverlight (WP7) loading a resource

查看:41
本文介绍了Silverlight (WP7) 加载资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码.它没有找到我的资源:

I have the following code. It's not finding my resource:

    string filename = "Resources/Functions.plist";
    Uri fileUri = new Uri(filename, UriKind.Relative);
    StreamResourceInfo sr = Application.GetResourceStream(fileUri);

但是上面执行后,sr为空.不好.

But after the above executes, sr is null. Not good.

我在名为Resources"的目录中有一个名为Functions.plist"的文件,该目录是我的项目目录的子目录.当我在解决方案资源管理器中右键单击它时,我看到它的构建操作为资源",并将其复制到输出目录为如果更新则复制".

I do have a file named "Functions.plist" in a directory named "Resources", which is a subdirectory of my project directory. When I right click it in the solution explorer, I see its build action as "Resource" and its copy to output directory as "copy if newer".

这是加载它的 .csproj 文件的一部分,或者至少我认为它是:

Here is the portion of the .csproj file that loads it, or at least I think it does:

<ItemGroup>
   // AppManifest and WMAppManifest here
<Resource Include="Resources\**">
   <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>

可能有什么问题?

推荐答案

原来我必须做的是使用以下内容将文件包含在项目中:

Turns out what I had to do was use the following to include the files in the project:

<ItemGroup>
  <None Include="Properties\AppManifest.xml">
    <SubType>Designer</SubType>
  </None>
  <None Include="Properties\foo.plist" />
  <None Include="Properties\WMAppManifest.xml">
    <SubType>Designer</SubType>
  </None>
  <Content Include="Resources\Functions.plist">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
  <Content Include="Resources\Help List.plist">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
            // and similarly for the other resource files
</ItemGroup>

我不确定,但关键可能是将资源"更改为内容".

I'm not sure, but the key may have been changing "Resource" to "Content".

这篇关于Silverlight (WP7) 加载资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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