C# 如何在windows phone 8的一个窗口中显示手机的mp3文件列表

C# 如何在windows phone 8的一个窗口中显示手机的mp3文件列表,c#,windows-phone-8,windows-phone,C#,Windows Phone 8,Windows Phone,我想在WindowsPhone8中使用代码隐藏语言c和XAML设计制作音乐播放器。我想在一个窗口中显示手机的mp3文件列表 如何在一个窗口中显示手机的mp3文件列表?如果您想列出手机媒体库中的歌曲列表,那么 创建一个基类模型 public class SongModel { public int songId { get; set; } public string songName { get; set; } } 生成全局变量 MediaLibrary mLibrary = n

我想在WindowsPhone8中使用代码隐藏语言c和XAML设计制作音乐播放器。我想在一个窗口中显示手机的mp3文件列表


如何在一个窗口中显示手机的mp3文件列表?

如果您想列出手机媒体库中的歌曲列表,那么

创建一个基类模型

public class SongModel
{
    public int songId { get; set; }
    public string songName { get; set; }
}
生成全局变量

MediaLibrary mLibrary = new MediaLibrary();
SongCollection songs;
List<SongModel> songnames;

我希望这能像预期的那样有所帮助

你好,阿穆,如果你能帮助我,我还想知道一件事?我想通过歌曲id更改媒体播放器的歌曲我将如何更改它?我被传给媒体播放器的歌曲列表保持不变。
songs = mLibrary.Songs;
MediaPlayer.ActiveSongChanged += MediaPlayer_ActiveSongChanged;
MediaPlayer.MediaStateChanged += MediaPlayer_MediaStateChanged;
if (songs.Count != 0)
{
    songnames = new List<SongModel>();
    for (int i = 0; i < songs.Count; i++)
    {
        songnames.Add(new SongModel() { songName = songs[i].Name, songId = i });
    }
    lbMusic.ItemsSource = songnames; // lbMusic is the list/listbox here
}
<ListBox  SelectionChanged="lbMusic_SelectionChanged" Foreground="Black" FontWeight="Bold" Name="lbMusic" Height="210" Width="480" Margin="0,10,0,0">
    <ListBox.ItemTemplate>
        <DataTemplate> 
            <StackPanel Margin="0,5,0,5" Width="480" Background="White" Height="40">
                <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding songName}" TextTrimming="WordEllipsis" Margin="30,0,0,0" Tag="{Binding songId}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
private void lbMusic_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    try
    {
        if (lbMusic.SelectedIndex != -1)
        {
            int musicId = (lbMusic.SelectedItem as SongModel).songId;
            MediaPlayer.Play(songs, musicId);
        }
    }
    catch
    {
        MessageBox.Show(TextResources.resErrorActiveSong);
    }
}