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".