/// <summary> /// Drag and Drop image /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AllPic_Drop(object sender, DragEventArgs e) { if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return; string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); bool isNewPic = false; foreach (var item in files) if (SearchPic.IsPicture(item)) { string filePath = Directory.GetCurrentDirectory() + @"\img\img"; string format = item.Substring(item.LastIndexOf("."), item.Length - item.LastIndexOf(".")); for (int i = 0; i < int.MaxValue; i++) if (!File.Exists(filePath + i + format)) { filePath += i + format; File.Copy(item, filePath); break; } gall.Add(new Gallery(item)); isNewPic = true; } if (isNewPic) { Dispatcher.Invoke(() => { AllPic.ItemsSource = null; AllPic.ItemsSource = gall; }); } }
/// <summary> /// Loading images /// </summary> private void LoadImg() { Dispatcher.Invoke(() => { gall = SearchPic.GetPic(); AllPic.ItemsSource = gall; }); }