Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从类库获取资源_C#_Windows Phone 7 - Fatal编程技术网

C# 如何从类库获取资源

C# 如何从类库获取资源,c#,windows-phone-7,C#,Windows Phone 7,我正在编写一个类库(WindowsPhone7目标),它有一个名为SoundFilePath 在最常见的场景中,调用WP应用程序将使用WAV文件的相对路径填充它。然后,类库将在某些事件中播放它 可以将此视为Windows Phone解决方案的简化树结构,该解决方案将使用MainPage.xaml中的my类库 WPSolution_ |_References | |_MyClassLibrary.dll |_M

我正在编写一个类库(WindowsPhone7目标),它有一个名为
SoundFilePath

在最常见的场景中,调用WP应用程序将使用WAV文件的相对路径填充它。然后,类库将在某些事件中播放它

可以将此视为Windows Phone解决方案的简化树结构,该解决方案将使用MainPage.xaml中的my类库

WPSolution_
           |_References
           |            |_MyClassLibrary.dll
           |_MainPage.xaml
           |_Sounds
           |            |_beep.wav
在MainPage.xaml中的某个地方,您将拥有:

var mcl = new MyClassLibrary();
mcl.SoundFilePath = "Sounds/beep.wav";  
我的问题是我的类库如何知道在哪里查找资源?

我尝试了以下几件事,但都没有成功:

Uri uri = new Uri(SoundFilePath , UriKind.Relative);
StreamResourceInfo sri = Application.GetResourceStream(uri); // sri was null

Gros Lalo提供的答复。只是必须将WAV的构建操作设置为内容。

WAV文件的构建目标是否设置为内容?我写这篇文章比实现(您的)解决方案花费的时间更长!谢谢很高兴听到这是一个容易解决的问题。