private void midiListView_KeyDown(object sender, KeyEventArgs e) { var listView = sender as ListView; if (MidiFiles.Count > 0 && listView.SelectedItems.Count > 0) { //delete item if (e.Key == Key.Delete || e.Key == Key.Back) { var list = new List <MidiFileObject>(); foreach (MidiFileObject item in listView.SelectedItems) { list.Add(item); } foreach (MidiFileObject item in list) { MidiFiles.Remove(item); } } if (listView.SelectedIndex == -1) { listView.SelectedItem = MidiFiles.LastOrDefault(); //选中最后一个 } } }
/* === MIDI导入 === */ private void importMidiBtn_Click(object sender, RoutedEventArgs e) { var beforeCount = MidiFiles.Count; var midiFileDialog = new Microsoft.Win32.OpenFileDialog { Title = "选择MIDI文件", Filter = "MIDI文件|*.mid", Multiselect = true }; if (midiFileDialog.ShowDialog() == true) { foreach (var path in midiFileDialog.FileNames) { MidiFiles.Add(new MidiFileObject(path)); } if (beforeCount != 0) { midiListView.SelectedItem = MidiFiles.LastOrDefault(); } } }