/* * 点击 - 批量删除图片 */ private void Batch_Delete_Click(object sender, RoutedEventArgs e) { List <StorageImage> list = new List <StorageImage>();//创建了一个空列表 List <Canvas> canvasList = new List <Canvas>(); UIElementCollection children = storageListWrap.Children; //1.获取所有勾选图片,同时移除选中 for (int i = 0; i < children.Count; i++) { Canvas canvas = (Canvas)children[i]; ImageListTag tag = (ImageListTag)canvas.Tag; if (tag.isSelected) { list.Add(tag.storageImage); canvasList.Add(canvas); } } DeleteImageWindow win = new DeleteImageWindow(storageListWrap, list, canvasList); win.ShowDialog(); ////3.删除数据库记录 //foreach (StorageImage storageImage in list) //{ // storageImageBll.delete(storageImage); //} ////4.从页面移除选中项 //foreach (Canvas canvas in canvasList) //{ // storageListWrap.Children.Remove(canvas); //} }
//选中所有 private void SelectAllFun() { foreach (Canvas image in storageListWrap.Children) { ImageListTag tag = (ImageListTag)image.Tag; if (!tag.isSelected) { selectThisImage(image); } } }
//勾选视频 private void selectButton(Canvas imageCanvas) { //移除所有 unselectedAllImage(); //选中当前 selectCurrImage(imageCanvas); //更新当前控件数据 ImageListTag tag = (ImageListTag)imageCanvas.Tag; currDControl.storageId = tag.storageImage.id; }
/* * 切换选中状态 */ private void toggleSelectStatus(Canvas image) { ImageListTag tag = (ImageListTag)image.Tag; if (tag.isSelected) { unSelectThisImage(image); } else { selectThisImage(image); } }
//鼠标离开视频 private void imageCanvasMouseLeave(object sender, MouseEventArgs e) { Canvas imageCanvas = (Canvas)sender; ImageListTag tag = (ImageListTag)imageCanvas.Tag; if (imageCanvas != null && !tag.isSelected) { FrameworkElement selectButton = FrameworkElementUtil.getByName(imageCanvas, "selectButton"); if (selectButton != null) { selectButton.Visibility = Visibility.Hidden; } } }
/* * 取消选中当前图片 */ private void unSelectThisImage(Canvas image) { ImageListTag tag = (ImageListTag)image.Tag; Button selectButton = (Button)FrameworkElementUtil.getByName(image, "selectButton"); if (selectButton != null) { selectButton.Visibility = Visibility.Hidden; selectButton.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(@"Resources/ico_media_select.png", UriKind.Relative)), Stretch = Stretch.UniformToFill }; } tag.isSelected = false; image.Tag = tag; }
//点击勾选视频 private void selectButtonClick(object sender, RoutedEventArgs e) { Canvas imageCanvas = null; FrameworkElement fe = (FrameworkElement)sender; if (fe.Name == "imageCanvas") { imageCanvas = (Canvas)fe; } else if (fe.Name == "selectButton") { imageCanvas = (Canvas)VisualTreeHelper.GetParent(fe); } ImageListTag tag = (ImageListTag)imageCanvas.Tag; toggleSelectStatus(imageCanvas); }
//选中当前视频 private void selectCurrImage(Canvas imageCanvas) { Button selectButton = (Button)FrameworkElementUtil.getByName(imageCanvas, "selectButton"); if (selectButton != null) { selectButton.Visibility = Visibility.Visible; selectButton.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(@"Resources/ico_media_select_active.png", UriKind.Relative)), Stretch = Stretch.UniformToFill }; } ImageListTag tag = (ImageListTag)imageCanvas.Tag; tag.isSelected = true; imageCanvas.Tag = tag; }
/* * 移动到 */ private void Batch_Move_To_Click(object sender, RoutedEventArgs e) { List <StorageImage> list = new List <StorageImage>();//创建了一个空列表 List <Canvas> canvasList = new List <Canvas>(); UIElementCollection children = storageListWrap.Children; //1.获取所有勾选图片,同时移除选中 for (int i = 0; i < children.Count; i++) { Canvas canvas = (Canvas)children[i]; ImageListTag tag = (ImageListTag)canvas.Tag; if (tag.isSelected) { list.Add(tag.storageImage); canvasList.Add(canvas); } } StorageImageMoveToFolderWindow win = new StorageImageMoveToFolderWindow(storageListWrap, list, canvasList); win.ShowDialog(); }
//public void DoEvents() //{ // DispatcherFrame frame = new DispatcherFrame(); // Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, // new DispatcherOperationCallback(ExitFrames), frame); // Dispatcher.PushFrame(frame); //} //public object ExitFrames(object f) //{ // ((DispatcherFrame)f).Continue = false; // return null; //} /* * 初始化一个图片控件 */ private Canvas initOneImage(StorageImage storageImage) { ImageListTag tag = new ImageListTag(); tag.isSelected = false; tag.storageImage = storageImage; Canvas imageCanvas = new Canvas(); imageCanvas.Name = "imageCanvas"; imageCanvas.Width = 100; imageCanvas.Height = 100; imageCanvas.Margin = new Thickness(10); imageCanvas.Tag = tag; //1.按钮 string imgFullPath = FileUtil.notExistsShowDefault(storageImage.url, Params.ImageNotExists); imgFullPath = AppDomain.CurrentDomain.BaseDirectory + imgFullPath; Image image = new Image(); image.Name = "image"; image.Width = 100; image.Height = 75; //image.Source = FileUtil.readImage2(imgFullPath,200); ; //image.Stretch = Stretch.Uniform; FileUtil.readImage2Image(image, imgFullPath, 200, Stretch.Uniform); //2.按钮行 Canvas bg = new Canvas(); bg.Name = "bg"; bg.Background = Brushes.Black; bg.Width = 100; bg.Height = 24; bg.Opacity = 0.6; bg.SetValue(Canvas.BottomProperty, 25.0); bg.SetValue(Canvas.LeftProperty, 0.0); //时长 Label lLabel = new Label(); lLabel.Width = 100; lLabel.Height = 24; lLabel.Content = storageImage.actualWidth + "×" + storageImage.actualHeight; lLabel.Foreground = Brushes.White; lLabel.SetValue(Canvas.LeftProperty, 0.0); lLabel.SetValue(Canvas.TopProperty, 0.0); bg.Children.Add(lLabel); //删除按钮 Button rbtn = new Button(); rbtn.Width = 16; rbtn.Height = 16; rbtn.BorderThickness = new Thickness(0); rbtn.Background = new ImageBrush { ImageSource = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + "/myfile/sysimg/ico-image-remove.png") , Stretch = Stretch.UniformToFill }; rbtn.SetValue(Canvas.RightProperty, -8.0); rbtn.SetValue(Canvas.TopProperty, -8.0); // bg.Children.Add(rbtn); // rbtn.Click += rbtnClick; //标题 Label titleLabel = new Label(); titleLabel.Width = 100; titleLabel.Height = 25; titleLabel.Content = storageImage.origFilename; titleLabel.SetValue(Canvas.LeftProperty, 0.0); titleLabel.SetValue(Canvas.BottomProperty, 0.0); titleLabel.ToolTip = titleLabel.Content; //勾选 Button selectButton = new Button(); selectButton.Name = "selectButton"; selectButton.Tag = storageImage.id; selectButton.Width = 24; selectButton.Height = 24; selectButton.BorderThickness = new Thickness(0); selectButton.SetValue(Canvas.LeftProperty, 7.0); selectButton.SetValue(Canvas.TopProperty, 7.0); selectButton.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(@"Resources/ico_media_select.png", UriKind.Relative)), Stretch = Stretch.UniformToFill }; selectButton.Visibility = Visibility.Hidden; imageCanvas.MouseEnter += imageCanvasMouseEnter; imageCanvas.MouseLeave += imageCanvasMouseLeave; imageCanvas.MouseLeftButtonDown += selectButtonClick; selectButton.Click += selectButtonClick; imageCanvas.Children.Add(image); imageCanvas.Children.Add(bg); imageCanvas.Children.Add(titleLabel); imageCanvas.Children.Add(selectButton); // videoCanvas.Children.Add(rbtn); return(imageCanvas); }