private void BigImage_Drop(object sender, DragEventArgs e) { //分为文件夹和文件 string[] dragdropFiles = (string[])e.Data.GetData(DataFormats.FileDrop); string file = dragdropFiles[0]; if (StaticClass.IsFile(file)) { FileInfo fileInfo = new FileInfo(file); if (fileInfo.Extension.ToLower() == ".jpg") { try { File.Copy(fileInfo.FullName, BasePicPath + $"BigPic\\{vieModel.DetailMovie.id.ToUpper()}.jpg", true); DetailMovie detailMovie = vieModel.DetailMovie; detailMovie.bigimage = null; vieModel.DetailMovie = null; detailMovie.bigimage = StaticClass.BitmapImageFromFile(fileInfo.FullName); vieModel.DetailMovie = detailMovie; RefreshUI("", fileInfo.FullName); } catch (Exception ex) { new Msgbox(this, ex.Message).ShowDialog(); } } else { new Msgbox(this, "仅支持 jpg").ShowDialog(); } } }
private void SetToBigPic(object sender, RoutedEventArgs e) { MenuItem m1 = sender as MenuItem; MenuItem m2 = m1.Parent as MenuItem; ContextMenu contextMenu = m2.Parent as ContextMenu; Image image = contextMenu.PlacementTarget as Image; StackPanel stackPanel = image.Parent as StackPanel; TextBlock textBox = stackPanel.Children.OfType <TextBlock>().First(); int idx = int.Parse(textBox.Text); string path = vieModel.DetailMovie.extraimagePath[idx]; if (!File.Exists(path)) { return; } try { File.Copy(path, BasePicPath + $"BigPic\\{vieModel.DetailMovie.id.ToUpper()}.jpg", true); //更新到 UI //BigImage.Source = new BitmapImage(new Uri(path)); DetailMovie detailMovie = vieModel.DetailMovie; detailMovie.bigimage = null; vieModel.DetailMovie = null; detailMovie.bigimage = StaticClass.BitmapImageFromFile(path); vieModel.DetailMovie = detailMovie; RefreshUI("", path); } catch (Exception ex) { new Msgbox(this, ex.Message).ShowDialog(); } }
private void RefreshUI(string smallPicPath, string BigPicPath = "") { windowMain = App.Current.Windows[0] as Main; for (int i = 0; i < windowMain.vieModel.CurrentMovieList.Count; i++) { try { if (windowMain.vieModel.CurrentMovieList[i]?.id.ToUpper() == vieModel.DetailMovie.id.ToUpper()) { Movie movie = windowMain.vieModel.CurrentMovieList[i]; if (smallPicPath != "") { movie.bigimage = null; } if (BigPicPath != "") { movie.smallimage = null; } windowMain.vieModel.CurrentMovieList[i] = null; if (smallPicPath != "") { movie.smallimage = StaticClass.BitmapImageFromFile(smallPicPath); } if (BigPicPath != "") { movie.bigimage = StaticClass.BitmapImageFromFile(BigPicPath); } windowMain.vieModel.CurrentMovieList[i] = movie; } } catch (Exception ex1) { Console.WriteLine(ex1.StackTrace); Console.WriteLine(ex1.Message); } } }