/* * 初始化一个图片控件 */ private Canvas initOneVideo(StorageVideo storageVideo) { VideoListTag tag = new VideoListTag(); tag.isSelected = false; tag.storageVideo = storageVideo; Canvas videoCanvas = new Canvas(); videoCanvas.Name = "videoCanvas"; videoCanvas.Width = 100; videoCanvas.Height = 100; videoCanvas.Margin = new Thickness(10); videoCanvas.Tag = tag; //1.按钮 StorageImage storageImage = storageImageBll.get(storageVideo.storageImageId); string imgFullPath = FileUtil.notExistsShowDefault(storageImage?.url, Params.ImageNotExists); imgFullPath = AppDomain.CurrentDomain.BaseDirectory + imgFullPath; Image videoImage = new Image(); videoImage.Name = "videoImage1"; videoImage.Width = 100; videoImage.Height = 75; videoImage.Source = FileUtil.readImage2(imgFullPath, 200); videoImage.Stretch = Stretch.UniformToFill; //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); //时长 string mmss = VideoUtil.duration2mmss(storageVideo.duration); Label lLabel = new Label(); lLabel.Width = 50; lLabel.Height = 24; lLabel.Content = mmss; 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 = storageVideo.origFilename; titleLabel.SetValue(Canvas.LeftProperty, 0.0); titleLabel.SetValue(Canvas.BottomProperty, 0.0); titleLabel.ToolTip = storageVideo.origFilename; //勾选 Button selectButton = new Button(); selectButton.Name = "selectButton"; selectButton.Tag = storageVideo.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; videoCanvas.MouseEnter += videoCanvasMouseEnter; videoCanvas.MouseLeave += videoCanvasMouseLeave; videoCanvas.MouseLeftButtonDown += selectButtonClick; selectButton.Click += selectButtonClick; videoCanvas.Children.Add(videoImage); videoCanvas.Children.Add(bg); videoCanvas.Children.Add(titleLabel); videoCanvas.Children.Add(selectButton); // videoCanvas.Children.Add(rbtn); return(videoCanvas); }
/* * 添加已选择的视频 */ private Canvas initSelectedVideo(StorageVideo video) { VideoListTag tag = new VideoListTag(); tag.isSelected = false; tag.storageVideo = video; Canvas selectedVideoCanvas = new Canvas(); selectedVideoCanvas.Name = "selectedVideoCanvas"; selectedVideoCanvas.Width = 100; selectedVideoCanvas.Height = 100; selectedVideoCanvas.Margin = new Thickness(10); selectedVideoCanvas.Tag = tag; //1.按钮 StorageImage storageImage = storageImageBll.get(video.storageImageId); string imgFullPath = FileUtil.notExistsShowDefault(storageImage?.url, Params.ImageNotExists); imgFullPath = AppDomain.CurrentDomain.BaseDirectory + imgFullPath; Image videoImage = new Image(); videoImage.Name = "videoImage1"; videoImage.Width = 100; videoImage.Height = 75; videoImage.Source = FileUtil.readImage2(imgFullPath, 200); videoImage.Stretch = Stretch.UniformToFill; //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); //时长 string mmss = VideoUtil.duration2mmss(video.duration); Label lLabel = new Label(); lLabel.Width = 50; lLabel.Height = 24; lLabel.Content = mmss; 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 + App.localStorage.icoRemove) , Stretch = Stretch.UniformToFill }; rbtn.SetValue(Canvas.RightProperty, -8.0); rbtn.SetValue(Canvas.TopProperty, -8.0); rbtn.Click += rbtnRemoveSelectedVideoClick; //标题 string videoFullPath = FileUtil.notExistsShowDefault(video?.url, Params.VideoNotExists); string fullFolder = FileUtil.getDirectory(AppDomain.CurrentDomain.BaseDirectory + videoFullPath); Label titleLabel = new Label(); titleLabel.Width = 100; titleLabel.Height = 25; titleLabel.Content = video.origFilename; titleLabel.Tag = fullFolder; titleLabel.SetValue(Canvas.LeftProperty, 0.0); titleLabel.SetValue(Canvas.BottomProperty, 0.0); titleLabel.ToolTip = video.origFilename; titleLabel.PreviewMouseLeftButtonUp += titleLabel_PreviewMouseLeftButtonUp; selectedVideoCanvas.Children.Add(videoImage); selectedVideoCanvas.Children.Add(bg); selectedVideoCanvas.Children.Add(titleLabel); selectedVideoCanvas.Children.Add(rbtn); return(selectedVideoCanvas); }