我希望用户从列表视图中选择一首歌并播放它。我试过:listview.SelectedValuePath
我收到错误:网址空白。我试过:listview.SelectedItem.ToString()
我收到错误:无效的网址。
Listview项文本是文件路径。所以不是这样。
我的完整代码:
FileOpenPicker picker = CreateFilePicker(audioExtensions);
IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();
if (files != null && files.Count > 0)
{
playlist = new Playlist();
foreach (StorageFile file in files)
{
playlist.Files.Add(file);
StorageFile savedFile =
await playlist.SaveAsAsync(KnownFolders.MusicLibrary,
"Sample",
NameCollisionOption.ReplaceExisting,
PlaylistFormat.WindowsMedia);
this.OutputStatus.Text = savedFile.Name + " was created and saved with "
+ playlist.Files.Count + " files."
+ Environment.NewLine + "At folder: "
+ savedFile.Path;
listview.Items.Add(file.Path.ToString());
}
}
else
{
this.OutputStatus.Text = "No files picked.";
}
我的列表视图已更改:
private void listview_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
media.Source = new Uri(listview.SelectedValuePath);
}
答案 0 :(得分:1)
第一个错误(Invalid Url Error)
修复是将ListViewItems添加到ListView中:How to Insert Object Type in ListView?
第二个错误(Invalid Source)
修复是从Selected ListViewItem获取Content
:
https://stackoverflow.com/a/9800781/2367343