点击文件
添加多选属性
绑定 OpenFileDialog窗口关闭事件
激活浏览绑定文件 添加到队列
/// <summary> /// 选择文件对话框事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SelectFilesButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog OFdialog = new OpenFileDialog(); ///对话框添加多选属性 OFdialog.Multiselect = true; try { ///判断浏览文件格式 if (!string.IsNullOrEmpty(_fileFilter)) OFdialog.Filter = _fileFilter; } catch (ArgumentException ex) { ///User supplied a wrong configuration file throw new Exception("Wrong file filter configuration.", ex); } if (OFdialog.ShowDialog() == true) { foreach (FileInfo file in OFdialog.Files) { UserFile userFile = new UserFile(); userFile.FileName = file.Name; userFile.FileStream = file.OpenRead(); if (userFile.FileStream.Length <= _maxFileSize) { ///向文件列表中添加文件信息 _files.Add(userFile); } else { MessageBoxControl.Message = "Maximum file size is: " + (_maxFileSize / 1024).ToString() + "KB."; MessageBoxControl.Visibility = Visibility.Visible; } } } }
_files.Add(userFile); 是一个文件集合类里面的添加方法
private FileCollection _files;