//选中所有
 private void SelectAllFun()
 {
     foreach (Canvas fileCanvas in storageListWrap.Children)
     {
         FileListTag tag = (FileListTag)fileCanvas.Tag;
         if (!tag.isSelected)
         {
             selectThisImage(fileCanvas);
         }
     }
 }
        //勾选视频
        private void selectButton(Canvas fileCanvas)
        {
            //移除所有
            unselectedAllImage();

            //选中当前
            selectCurrImage(fileCanvas);

            //更新当前控件数据
            FileListTag tag = (FileListTag)fileCanvas.Tag;

            currDControl.storageId = tag.storageFile.id;
        }
        /*
         * 切换选中状态
         */
        private void toggleSelectStatus(Canvas fileCanvas)
        {
            FileListTag tag = (FileListTag)fileCanvas.Tag;

            if (tag.isSelected)
            {
                unSelectThisImage(fileCanvas);
            }
            else
            {
                selectThisImage(fileCanvas);
            }
        }
        //鼠标离开视频
        private void imageCanvasMouseLeave(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.Hidden;
                }
            }
        }
        /*
         * 取消选中当前图片
         */
        private void unSelectThisImage(Canvas fileCanvas)
        {
            FileListTag tag          = (FileListTag)fileCanvas.Tag;
            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;
        }
        //点击勾选视频
        private void selectButtonClick(object sender, RoutedEventArgs e)
        {
            Canvas           fileCanvas = null;
            FrameworkElement fe         = (FrameworkElement)sender;

            if (fe.Name == "fileCanvas")
            {
                fileCanvas = (Canvas)fe;
            }
            else if (fe.Name == "selectButton")
            {
                fileCanvas = (Canvas)VisualTreeHelper.GetParent(fe);
            }
            FileListTag tag = (FileListTag)fileCanvas.Tag;

            toggleSelectStatus(fileCanvas);
        }
        /*
         * 移动到
         */
        private void Batch_Move_To_Click(object sender, RoutedEventArgs e)
        {
            List <StorageFile>  list       = new List <StorageFile>();//创建了一个空列表
            List <Canvas>       canvasList = new List <Canvas>();
            UIElementCollection children   = storageListWrap.Children;

            //1.获取所有勾选图片,同时移除选中
            for (int i = 0; i < children.Count; i++)
            {
                Canvas      canvas = (Canvas)children[i];
                FileListTag tag    = (FileListTag)canvas.Tag;
                if (tag.isSelected)
                {
                    list.Add(tag.storageFile);
                    canvasList.Add(canvas);
                }
            }
            StorageFileMoveToFolderWindow win = new StorageFileMoveToFolderWindow(storageListWrap, list, canvasList);

            win.ShowDialog();
        }
        /*
         * 点击 - 批量删除图片
         */
        private void Batch_Delete_Click(object sender, RoutedEventArgs e)
        {
            List <StorageFile>  list       = new List <StorageFile>();//创建了一个空列表
            List <Canvas>       canvasList = new List <Canvas>();
            UIElementCollection children   = storageListWrap.Children;

            //1.获取所有勾选图片,同时移除选中
            for (int i = 0; i < children.Count; i++)
            {
                Canvas      canvas = (Canvas)children[i];
                FileListTag tag    = (FileListTag)canvas.Tag;
                if (tag.isSelected)
                {
                    list.Add(tag.storageFile);
                    canvasList.Add(canvas);
                }
            }

            DeleteFileWindow win = new DeleteFileWindow(storageListWrap, list, canvasList);

            win.ShowDialog();


            ////3.删除数据库记录
            //foreach (StorageFile storageFile in list)
            //{
            //    int row = storageFileBll.delete(storageFile);
            //}


            ////4.从页面移除选中项
            //foreach (Canvas canvas in canvasList)
            //{
            //    storageListWrap.Children.Remove(canvas);
            //}
        }
        /*
         * 初始化一个图片控件
         */
        private Canvas initOneFile(StorageFile storageFile)
        {
            FileListTag tag = new FileListTag();

            tag.isSelected  = false;
            tag.storageFile = storageFile;
            Canvas fileCanvas = new Canvas();

            fileCanvas.Name   = "fileCanvas";
            fileCanvas.Width  = 100;
            fileCanvas.Height = 100;
            fileCanvas.Margin = new Thickness(10);
            fileCanvas.Tag    = tag;

            //1.按钮
            string imgFullPath = "/myfile/sysimg/file/ico_other.png";

            if (storageFile.ext == ".doc" || storageFile.ext == ".docx" || storageFile.ext == ".xps")
            {
                imgFullPath = "/myfile/sysimg/file/ico_word.png";
            }
            else if (storageFile.ext == ".pdf")
            {
                imgFullPath = "/myfile/sysimg/file/ico_pdf.png";
            }
            else if (storageFile.ext == ".mp3")
            {
                imgFullPath = "/myfile/sysimg/file/ico_mp3.png";
            }
            imgFullPath = FileUtil.notExistsShowDefault(imgFullPath, 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    = FileUtil.ByteToKB(storageFile.size);
            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 = storageFile.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             = storageFile.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;



            fileCanvas.MouseEnter          += imageCanvasMouseEnter;
            fileCanvas.MouseLeave          += imageCanvasMouseLeave;
            fileCanvas.MouseLeftButtonDown += selectButtonClick;
            selectButton.Click             += selectButtonClick;



            fileCanvas.Children.Add(image);
            fileCanvas.Children.Add(bg);
            fileCanvas.Children.Add(titleLabel);
            fileCanvas.Children.Add(selectButton);
            // videoCanvas.Children.Add(rbtn);

            return(fileCanvas);
        }