コード例 #1
0
        private void OpenBtn_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog
            Microsoft.Win32.OpenFileDialog openFileDlg = new Microsoft.Win32.OpenFileDialog
            {
                Filter = "Media Files | *.mp3;*.m4a;*.wma;*.wav "
            };

            // Launch OpenFileDialog by calling ShowDialog method
            Nullable <bool> result = openFileDlg.ShowDialog();

            // Get the selected file name and display in a TextBox.
            // Load content of file in a TextBlock
            if (result == true)
            {
                Song s = musicLib.AddSong(openFileDlg.FileName);

                displayedSongs.Clear();
                foreach (DataRow row in musicLib.Songs.Rows)
                {
                    Song song = musicLib.GetSong(int.Parse(row["id"].ToString()));
                    displayedSongs.Add(song);

                    if (song.Id == s.Id)
                    {
                        dataGrid.SelectedItem = song;
                    }
                }

                dataGrid.Items.Refresh();
            }
        }
コード例 #2
0
        private void Add_Song_Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Media Files (*.mp3;*.m4a;*.wma;*.wav)|*.mp3;*.m4a;*.wma;*.wav|MP3 (*.mp3)|*.mp3|M4A (*.m4a)|*.m4a|Windows Media Audio (*.wma)|*wma|Wave Files (*.wav)|*.wav|All files (*.*)|*.*";
            if (openFileDialog.ShowDialog() == true)
            {
                Song s   = musicLib.AddSong(openFileDialog.FileName);
                int  sID = s.Id;
                highligtNewSong();
            }
        }
コード例 #3
0
        //This is used in previous projects!!!
        public void AddSong(string sondata)
        {
            // Add the selected file to the music library
            Song s = GetSongDetails(sondata);

            musicLib.AddSong(s);
            musicLib.Save();
            DataView temp = dataGrid.ItemsSource as DataView;

            temp.Sort = "id";
            int songID = temp.Find(s.Id);

            dataGrid.SelectedIndex = songID;
        }
コード例 #4
0
        private void Open_File_Explorer(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Music Files ( *.mp3, *.m4a, *.wma, *.wav )|*.mp3;*.m4a;*.wma;*.wav;|All files (*.*)|*.*";
            if (openFileDialog.ShowDialog() == true)
            {
                string filePath = openFileDialog.FileName;
                Song   s        = musicLibrary.AddSong(filePath);
                playListBox.SelectedItem = playListBox.Items[0];
                songGrid.SelectedItem    = songGrid.Items[0];
                DataRowView currentItem = songGrid.SelectedItem as DataRowView;
                int         id          = (int)currentItem["id"];

                int index = 0;
                while (id != s.Id)
                {
                    index++;
                    songGrid.SelectedItem = songGrid.Items[index];
                    currentItem           = songGrid.SelectedItem as DataRowView;
                    id = (int)currentItem["id"];
                }
            }
        }