我的课程有一个媒体播放器项目。我有一个列表歌曲:
<ListBox Name="listBoxSongs" SelectionChanged="listBoxSongs_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="100" Margin="8" Source="{Binding Image}"/>
<StackPanel >
<TextBlock Foreground="{StaticResource PhoneAccentBrush}" Text="{Binding Title}" TextWrapping="Wrap" FontSize="24" />
<TextBlock VerticalAlignment="Center" Text="{Binding Artist}" TextWrapping="Wrap"/>
</StackPanel>
<TextBlock Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding Duration}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
下面的代码使用媒体库并使用列表视图显示歌曲列表:
foreach (Song song in songs)
{
if (song != null)
mySongs.Add(new MySongs()
{
Artist = song.Artist.ToString(),
Title = song.Name,
Duration = (new DateTime(song.Duration.Ticks)).ToString("mm:ss")
});
else
{
TextBlock msg = new TextBlock();
msg.Text = "no music";
listBoxSongs.Items.Add(msg);
}
if (song.Album.HasArt)
{
BitmapImage img = new BitmapImage();
img.SetSource(song.Album.GetAlbumArt());
mySongs.Last().Image = img;
}
else
mySongs.Last().Image = new BitmapImage(new Uri("Images/noArt.png", UriKind.Relative));
}
listBoxSongs.ItemsSource = mySongs;
当我单击 listview 项目时,如何导航到“mainPage.xaml”并从我的列表中播放歌曲?