WPF,这个资源文件路径该怎么写?
一个项目,结构图如下:
在UserControl1后台:
void UserControl1_Loaded(object sender, RoutedEventArgs e)
{
string s1 = "pack://application:,,,/WPF2;component/aa/2.png";
image1.Source = new BitmapImage(new Uri(s1));
string s2 = "pack://application:,,,/WPF2;component/aa/Sound1.wav"; //与上面一句一样,为什么报错
SoundPlayer player1 = new SoundPlayer(s2);
player1.Play();
}
代码中,引用2.png图片的代码没有报错,引用Sound1的代码和引用2.png文件的代码是一样的,为什么又报错呢?
------解决方案--------------------
右键音乐文件Sound1.wav属性,生成属性改成 嵌入的资源
------解决方案--------------------
加上new Uri看一下:
SoundPlayer player1 = new SoundPlayer(new Uri(s2));
------解决方案--------------------
参考:
URI Prefix n