//勾选视频 private void selectButton(Canvas imageCanvas) { //移除所有 unselectedAllImage(); //选中当前 selectCurrImage(imageCanvas); //更新当前控件数据 GifListTag tag = (GifListTag)imageCanvas.Tag; currDControl.storageId = tag.storageGif.id; }
//鼠标离开视频 private void imageCanvasMouseLeave(object sender, MouseEventArgs e) { Canvas imageCanvas = (Canvas)sender; GifListTag tag = (GifListTag)imageCanvas.Tag; if (imageCanvas != null && !tag.isSelected) { FrameworkElement selectButton = FrameworkElementUtil.getByName(imageCanvas, "selectButton"); if (selectButton != null) { selectButton.Visibility = Visibility.Hidden; } } }
//选中当前视频 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 }; } GifListTag tag = (GifListTag)imageCanvas.Tag; tag.isSelected = true; imageCanvas.Tag = tag; }
//取消所有视频选中状态 private void unselectedAllImage() { foreach (Canvas image in imageListWrap.Children) { GifListTag tag = (GifListTag)image.Tag; if (tag.isSelected) { 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; } } }
//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(StorageGif storageGif) { GifListTag tag = new GifListTag(); tag.isSelected = false; tag.storageGif = storageGif; 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(storageGif.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; //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 = storageGif.actualWidth + "×" + storageGif.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 = storageGif.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 = storageGif.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); }