【发布时间】:2023-02-07 17:50:22
【问题描述】:
目前在这里试验 WPF。我正在尝试使用 URI 文件在表格中存储音乐。
它目前有效,但正如预期的那样只在我的电脑上,因为它是一个绝对路径:
private readonly Uri[] SoundsTable = new Uri[] { new Uri(@"C:\Users\damie\Desktop\repos2\Tetrics\Tetrics\Assets\music_theme.wav"), new Uri(@"C:\Users\damie\Desktop\repos2\Tetrics\Tetrics\Assets\line_clear.wav"), };
我遇到了编译后无法访问我的音乐文件的问题。我无法使用相对路径或确定它获取 Path.CurrentDirectory() (因为我的资产文件夹未在编译项目中生成)。
对于可以存储在我的 DLL 中的图像,我没有这个问题:
`private readonly ImageSource[] tileImages = new ImageSource[] {
new BitmapImage(new Uri("Assets/TileEmpty.png", UriKind.Relative)),
new BitmapImage(new Uri("Assets/TileCyan.png", UriKind.Relative)),
new BitmapImage(new Uri("Assets/TileBlue.png", UriKind.Relative)),
new BitmapImage(new Uri("Assets/TileOrange.png", UriKind.Relative)),
new BitmapImage(new Uri("Assets/TileYellow.png", UriKind.Relative)),
new BitmapImage(new Uri("Assets/TileGreen.png", UriKind.Relative)),
new BitmapImage(new Uri("Assets/TilePurple.png", UriKind.Relative)),
new BitmapImage(new Uri("Assets/TileRed.png", UriKind.Relative))
};`
有谁知道在这里做什么?
我试图更改音乐文件的 IDE 属性,例如构建操作和复制到输出文件夹。 我想我的答案可能在这里,但我尝试过的都没有奏效。
非常感谢任何回应的人!
【问题讨论】: