0

コース用のメディア プレーヤー プロジェクトがあります。私はリストの曲を持っています:

<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;

「mainPage.xaml」に移動して、リストビュー アイテムをクリックしたときにリストから曲を再生するにはどうすればよいですか?

4

0 に答える 0