private void RandomImg_MouseDown(object sender, MouseButtonEventArgs e) { if (RandomImg.Source == FindResource("RandomButton") as ImageSource) { RandomImg.Source = FindResource("NotRandomButton") as ImageSource; prevPlayList = new PlayList(); prevPlayList.Items.AddRange(collectionOfPlayLists.currentPlayList.Items); collectionOfPlayLists.currentPlayList.RandomTheList(); } else { RandomImg.Source = FindResource("RandomButton") as ImageSource; collectionOfPlayLists.currentPlayList = prevPlayList; } if (playListWindow != null) { playListWindow.playListView.Items.Clear(); playListWindow.InitPlayListView(collectionOfPlayLists.currentPlayList); } }
public void InitPlayListView(PlayList playList) { if (playList.Items.Count != 0) { string prevFolder = ""; System.IO.FileInfo file = new System.IO.FileInfo(playList.Items[0].Path); prevFolder = file.Directory.Name; for (int i = 0; i < playList.Items.Count; i++) { if (i == 0 || prevFolder != new System.IO.FileInfo(playList.Items[i].Path).Directory.Name) { prevFolder = new System.IO.FileInfo(playList.Items[i].Path).Directory.Name; ListViewItem itemHeader = new ListViewItem(); itemHeader.Height = 48; Grid gridHeader = new Grid(); gridHeader.Height = 48; Label labelNameOfFolder = new Label(); labelNameOfFolder.Name = "NumberOfTrack"; labelNameOfFolder.Content = prevFolder; labelNameOfFolder.FontSize = 19; labelNameOfFolder.Foreground = new SolidColorBrush(Color.FromArgb(255, 191, 53, 23)); labelNameOfFolder.Margin = new Thickness(0, 0, 486, 0); gridHeader.Children.Add(labelNameOfFolder); itemHeader.Content = gridHeader; playListView.Items.Add(itemHeader); } ListViewItem item = new ListViewItem(); item.Height = 48; Grid grid = new Grid(); grid.Height = 48; grid.Margin = new Thickness(20, 0, 0, 0); Label labelNumberOfTrack = new Label(); labelNumberOfTrack.Name = "NumberOfTrack"; labelNumberOfTrack.Content = i + 1 + "."; labelNumberOfTrack.FontSize = 13.5; labelNumberOfTrack.Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128)); labelNumberOfTrack.Margin = new Thickness(0, 0, 486, 0); Label labelNameOfTrackAndComposer = new Label(); labelNameOfTrackAndComposer.Name = "NameOfTrackAndComposer"; labelNameOfTrackAndComposer.Content = playList.Items[i].Compositor + " - " + playList.Items[i].Name; labelNameOfTrackAndComposer.FontSize = 13.5; labelNameOfTrackAndComposer.Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128)); labelNameOfTrackAndComposer.Margin = new Thickness(29, 0, 271, 0); Label labelDurationOfTrack = new Label(); labelDurationOfTrack.Name = "DurationOfTrack"; labelDurationOfTrack.Content = TimeSpan.FromSeconds(playList.Items[i].Seconds).ToString(@"mm\:ss"); labelDurationOfTrack.FontSize = 13.5; labelDurationOfTrack.Foreground = new SolidColorBrush(Color.FromRgb(128, 128, 128)); labelDurationOfTrack.Margin = new Thickness(350, 0, 126, 0); Label labelExtAndSize = new Label(); labelExtAndSize.Name = "ExtAndSize"; labelExtAndSize.Content = playList.Items[i].ShortToString(); labelExtAndSize.FontSize = 11; labelExtAndSize.Foreground = new SolidColorBrush(Color.FromRgb(169, 169, 169)); labelExtAndSize.Margin = new Thickness(0, 23, 486, -23); grid.Children.Add(labelNumberOfTrack); grid.Children.Add(labelNameOfTrackAndComposer); grid.Children.Add(labelDurationOfTrack); grid.Children.Add(labelExtAndSize); item.Content = grid as object; item.MouseDoubleClick += ListViewItem_MouseDown; playListView.Items.Add(item); } } labelCountOfItemsPlayList.Content = playList.Items.Count; labelSumTimeOfPlayList.Content = TimeSpan.FromSeconds(playList.TotalTimeInSeconds()).ToString("dd\\:hh\\:mm\\:ss"); labelSizeOfItemsPlayList.Content = PlayItem.BytesToString(playList.TotalSizeInBytes()); }