/* * 清空控件中的图片 */ private void removeBtnClick(object sender, RoutedEventArgs e) { Button removeBtn = (Button)sender; Canvas bg = (Canvas)VisualTreeHelper.GetParent(removeBtn); Canvas imgCanvas = (Canvas)VisualTreeHelper.GetParent(bg); object tag = imgCanvas.Tag; if (tag == null) { return; } TurnPictureImagesDto dto = (TurnPictureImagesDto)tag; dto.url = ""; dto.storageImageId = 0; imgCanvas.Tag = dto; Button imgBtn = (Button)FrameworkElementUtil.getByName(imgCanvas, "imgBtn"); imgBtn.Background = new ImageBrush { ImageSource = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + defaultBg) , Stretch = Stretch.Uniform }; }
/* *右击树,显示菜单 */ private void StorageVideo_TreeView_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { // MessageBox.Show(e.Source.GetType().Name); if (e.Source.GetType().Name != "TreeViewItem") { e.Handled = true; return; } // object or = e.Source; try { TreeViewItem treeViewItem = (TreeViewItem)e.Source; rightClickTreeViewItem = treeViewItem; Object tag = treeViewItem.Tag; if (tag != null) { Int32 folderId = Int32.Parse(tag.ToString()); rightClickFolderId = folderId; treeViewItem.Focus(); folderTreeColumn.ContextMenu.IsOpen = true; ItemCollection firstItems = folderTreeColumn.ContextMenu.Items; FrameworkElementUtil.enableAllMenuItem(firstItems); if (folderId == 1) { // MenuItem NewAfterPage = FrameworkElementUtil.getByName(firstItems, "NewAfterPage"); MenuItem MoveUp = FrameworkElementUtil.getByName(firstItems, "MoveUp"); MenuItem MoveDown = FrameworkElementUtil.getByName(firstItems, "MoveDown"); MenuItem DeleteFolder = FrameworkElementUtil.getByName(firstItems, "DeleteFolder"); // NewAfterPage.IsEnabled = false; MoveUp.IsEnabled = false; MoveDown.IsEnabled = false; DeleteFolder.IsEnabled = false; } } else { MessageBox.Show("没有tag:" + treeViewItem.Header.ToString()); } } catch (ArgumentNullException) { MessageBox.Show("页面不能为空"); } catch (ArgumentException) { MessageBox.Show("页面地址异常"); } catch (UriFormatException) { MessageBox.Show("页面地址格式化异常"); } catch (Exception e4) { MessageBox.Show("找不到此页面" + e4.Message.ToString() + e4.StackTrace); } }
/* * 上下左右,移动控件 */ public Boolean KeyDownMove(Key key) { Boolean result = false; FrameworkElement element = FrameworkElementUtil.getByName(container, "editingBorder"); if (element == null) { return(result); } Border editingBorder = (Border)element; FrameworkElement control = (FrameworkElement)editingBorder.Tag; Thickness margin = control.Margin; if (key == Key.Up) { margin.Top = margin.Top - 1; control.Margin = margin; editingBorder.Margin = margin; result = true; } else if (key == Key.Down) { margin.Top = margin.Top + 1; control.Margin = margin; editingBorder.Margin = margin; result = true; } else if (key == Key.Left) { margin.Left = margin.Left - 1; control.Margin = margin; editingBorder.Margin = margin; result = true; } else if (key == Key.Right) { margin.Left = margin.Left + 1; control.Margin = margin; editingBorder.Margin = margin; result = true; } if (result) { DControl dc = (DControl)control.Tag; dc.left = (Int32)control.Margin.Left; dc.top = (Int32)control.Margin.Top; control.Tag = dc; dControlBll.update(dc); } return(result); }
//鼠标离开视频 private void videoCanvasMouseLeave(object sender, MouseEventArgs e) { Canvas videoCanvas = (Canvas)sender; VideoListTag tag = (VideoListTag)videoCanvas.Tag; if (videoCanvas != null && !tag.isSelected) { FrameworkElement selectButton = FrameworkElementUtil.getByName(videoCanvas, "selectButton"); if (selectButton != null) { selectButton.Visibility = Visibility.Hidden; } } }
//鼠标移动到视频上 private void imageCanvasMouseEnter(object sender, MouseEventArgs e) { Canvas fileCanvas = (Canvas)sender; FileListTag tag = (FileListTag)fileCanvas.Tag; if (fileCanvas != null && !tag.isSelected) { FrameworkElement selectButton = FrameworkElementUtil.getByName(fileCanvas, "selectButton"); if (selectButton != null) { selectButton.Visibility = Visibility.Visible; } } }
/* * 取消选中当前图片 */ private void unSelectThisImage(Canvas video) { VideoListTag tag = (VideoListTag)video.Tag; Button selectButton = (Button)FrameworkElementUtil.getByName(video, "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; video.Tag = tag; }
/* * 选中当前图片 */ private void selectThisImage(Canvas fileCanvas) { FileListTag tag = (FileListTag)fileCanvas.Tag; Button selectButton = (Button)FrameworkElementUtil.getByName(fileCanvas, "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 }; } tag.isSelected = true; fileCanvas.Tag = tag; }
//取消所有视频选中状态 private void unselectedAllImage() { foreach (Canvas fileCanvas in imageListWrap.Children) { FileListTag tag = (FileListTag)fileCanvas.Tag; if (tag.isSelected) { Button selectButton = (Button)FrameworkElementUtil.getByName(fileCanvas, "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; fileCanvas.Tag = tag; } } }
/* * 显示大图 */ public static void showBigImage(string imagePath, DControlDto ctl, Grid mainContainer, Cfg cfg) { FrameworkElement bigImageElement = FrameworkElementUtil.getByName(mainContainer, "bigImageCanvas"); if (bigImageElement == null) { Canvas bigImageCanvas = new Canvas(); bigImageCanvas.Name = "bigImageCanvas"; bigImageCanvas.Width = cfg.screenWidth; bigImageCanvas.Height = cfg.screenHeight; bigImageCanvas.Background = Brushes.Transparent; Panel.SetZIndex(bigImageCanvas, 10002); //图片背景,点击隐藏 Border borderBg = new Border(); borderBg.Width = cfg.screenWidth; borderBg.Height = cfg.screenHeight; borderBg.Background = Brushes.Black; borderBg.Opacity = 0.6; borderBg.HorizontalAlignment = HorizontalAlignment.Left; borderBg.VerticalAlignment = VerticalAlignment.Top; borderBg.SetValue(Canvas.LeftProperty, 0.0); borderBg.SetValue(Canvas.TopProperty, 0.0); Panel.SetZIndex(borderBg, 1); bigImageCanvas.Children.Add(borderBg); //显示大图 double maxWidth = cfg.screenWidth * 0.9; double maxHeight = cfg.screenHeight * 0.9; string img = FileUtil.notExistsShowDefault(imagePath, Params.ImageNotExists); BitmapImage bitmapImage = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + img); double showWidth = bitmapImage.Width; double showHeight = bitmapImage.Height; double w = bitmapImage.Width / maxWidth; double h = bitmapImage.Height / maxHeight; if (w > 1 && h > 1) { if (w > h) { showWidth = maxWidth; showHeight = bitmapImage.Height / w; } else { showHeight = maxHeight; showWidth = bitmapImage.Width / h; } } else if (w > 1) { showWidth = maxWidth; showHeight = bitmapImage.Height / w; } else if (h > 1) { showHeight = maxHeight; showWidth = bitmapImage.Width / h; } Canvas innerCanvas = new Canvas(); innerCanvas.Width = showWidth; innerCanvas.Height = showHeight; double left = ctl.left; double top = ctl.top; innerCanvas.SetValue(Canvas.LeftProperty, left); innerCanvas.SetValue(Canvas.TopProperty, top); Panel.SetZIndex(innerCanvas, 2); Image image = new Image(); image.Source = bitmapImage; image.Width = showWidth; image.Height = showHeight; Panel.SetZIndex(image, 1); innerCanvas.Children.Add(image); Button closebtn = new Button(); closebtn.Background = new ImageBrush { ImageSource = FileUtil.readImage(AppDomain.CurrentDomain.BaseDirectory + "/myfile/sysimg/ico-image-close.png") , Stretch = Stretch.Fill }; closebtn.Width = 50; closebtn.Height = 50; closebtn.BorderThickness = new Thickness(0); closebtn.HorizontalAlignment = HorizontalAlignment.Right; closebtn.VerticalAlignment = VerticalAlignment.Top; closebtn.SetValue(Canvas.RightProperty, -25.0); closebtn.SetValue(Canvas.TopProperty, -25.0); Panel.SetZIndex(closebtn, 2); closebtn.Click += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer); closebtn.PreviewTouchDown += imageCloseBtnTouchDown; closebtn.PreviewTouchMove += imageCloseBtnTouchMove; closebtn.PreviewTouchUp += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer); innerCanvas.Children.Add(closebtn); bigImageCanvas.Children.Add(innerCanvas); borderBg.PreviewMouseUp += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer); borderBg.PreviewTouchUp += (sender, e) => imageCloseBtnClick(bigImageCanvas, borderBg, innerCanvas, ctl, mainContainer); //手指缩放 移动 旋转 BehaviorCollection behaviors = Interaction.GetBehaviors(innerCanvas); TranslateZoomRotateBehavior tz = new TranslateZoomRotateBehavior(); tz.TranslateFriction = 0.3; tz.RotationalFriction = 0.4; tz.ConstrainToParentBounds = true; tz.SupportedGestures = ManipulationModes.All; behaviors.Add(tz); TransformGroup group = new TransformGroup(); double scaleX = ctl.width / innerCanvas.Width; double scaleY = ctl.height / innerCanvas.Height; ScaleTransform scaleTransform = new ScaleTransform(); scaleTransform.ScaleX = scaleX; scaleTransform.ScaleY = scaleY; group.Children.Add(scaleTransform); innerCanvas.RenderTransform = group; //动画,平移到指定位置 double toLeft = (cfg.screenWidth - innerCanvas.Width) / 2; double toTop = (cfg.screenHeight - innerCanvas.Height) / 2; double toTranslateTransformX = toLeft - ctl.left; double toTranslateTransformY = toTop - ctl.top; ShowBigImageUtil.showAnimation(borderBg, innerCanvas, ctl, toTranslateTransformX, toTranslateTransformY); mainContainer.Children.Add(bigImageCanvas); } }