private void UserControl_Drop(object sender, DragEventArgs e) { var vm = this.DataContext as FileStarterViewModel; var list = vm.FileInfoList; var pathList = vm.FileInfoList.Select(x => x.FilePath); var DuplicateFilePathList = new List <string>(); if (!(e.Data.GetData(DataFormats.FileDrop) is string[] files)) { return; } foreach (var s in files) { if (Directory.Exists(s)) { continue; } if (pathList.Contains(s)) { DuplicateFilePathList.Add(s); continue; } var fileInfo = new FileAccessor.FileInfo { FilePath = s, FileName = System.IO.Path.GetFileName(s) }; if (File.Exists(s)) { var icon = System.Drawing.Icon.ExtractAssociatedIcon(s); fileInfo.Icon = Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } list.Add(fileInfo); vm.SynchronizeDisplayFileList(); var extension = Path.GetExtension(s); var extensionItems = vm.ExtensionList.Where(x => x.Name == extension); if (!extensionItems.Any()) { foreach (var extItem in extensionItems) { vm.ExtensionList.Add(extItem); } } } if (DuplicateFilePathList.Any()) { var message = "下記のアイテムは既に登録済みのため登録されませんでした。\n"; foreach (var item in DuplicateFilePathList) { message += " " + item + "\n"; } MessageBox.Show(message); } this.WatermarkTextBox.Visibility = Visibility.Collapsed; }
public FileStarterViewModel() : base() { ExeInfoList = new ObservableCollection <FileAccessor.FileInfo>(); DisplayExeInfoList = new ObservableCollection <FileAccessor.FileInfo>(); SelectedExeInfo = new FileAccessor.FileInfo(); SettingProcessStartCommand = new DelegateCommand(SettingProcessStart, CanSettingProcessStart); }