/*
         * 1.1 右击图片或编辑框
         */
        internal void control_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            FrameworkElement ele = (FrameworkElement)sender;

            if (ele.GetType().Name == "Border")
            {
                ele = (FrameworkElement)ele.Tag;
            }
            else
            {
                Border editingBorder = control_GetFocus(sender, e);
            }
            DControl dControl = (DControl)ele.Tag;

            //this.rightClickDControl = dControl;
            rightClickEle = ele;



            //目标
            // ele.ContextMenu.PlacementTarget = this.btnMenu;
            //位置
            // ele.ContextMenu.Placement = PlacementMode.Top;
            //显示菜单

            if (dControl.type == "Image")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "ImageContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "TurnPicture")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "TurnPictureContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "Marque")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "MarqueContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "MarqueLayer")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "MarqueLayerContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "Word")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "WordContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "Video")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "VideoContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "BackButton")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "BackButtonContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "HomeButton")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "HomeButtonContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "CFrame")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "CFrameContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "TextBlock")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "TextBlockContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "Gif")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "GifContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "CCalendar")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "CCalendarContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            else if (dControl.type == "CAudio")
            {
                Grid xContextMenu = FrameworkElementUtil.GetChildObject <Grid>(pageTemplate.container, "CAudioContextMenu");
                xContextMenu.ContextMenu.IsOpen = true;
            }
            e.Handled = true;
        }
        /*
         * 保存数据
         */
        private void Submit_Button_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(backgroundMusicButtonLeft.Text))
            {
                MessageBox.Show("请填写按钮左边距;"); return;
            }
            else if (!DataUtil.isInt(backgroundMusicButtonLeft.Text.ToString()))
            {
                MessageBox.Show("按钮左边距必须是整数;"); return;
            }
            if (string.IsNullOrWhiteSpace(backgroundMusicButtonTop.Text.ToString()))
            {
                MessageBox.Show("请填写按钮上边距;"); return;
            }
            else if (!DataUtil.isInt(backgroundMusicButtonTop.Text.ToString()))
            {
                MessageBox.Show("按钮上边距必须是整数;"); return;
            }

            if (string.IsNullOrWhiteSpace(backgroundMusicButtonWidth.Text))
            {
                MessageBox.Show("请填写按钮宽度;"); return;
            }
            else if (!DataUtil.isInt(backgroundMusicButtonLeft.Text.ToString()))
            {
                MessageBox.Show("按钮宽度必须是整数;"); return;
            }
            if (string.IsNullOrWhiteSpace(backgroundMusicButtonHeight.Text.ToString()))
            {
                MessageBox.Show("请填写按钮高度;"); return;
            }
            else if (!DataUtil.isInt(backgroundMusicButtonTop.Text.ToString()))
            {
                MessageBox.Show("按钮高度必须是整数;"); return;
            }

            //1.更新到数据库
            Cfg cfg = cfgBll.get(1);

            cfg.backgroundMusicShow     = (bool)backgroundMusicShow.IsChecked;
            cfg.backgroundMusicAutoplay = (bool)backgroundMusicAutoplay.IsChecked;
            cfg.backgroundMusicLoop     = (bool)backgroundMusicLoop.IsChecked;

            cfg.backgroundMusicButtonWidth  = int.Parse(backgroundMusicButtonWidth.Text);
            cfg.backgroundMusicButtonHeight = int.Parse(backgroundMusicButtonHeight.Text);
            cfg.backgroundMusicButtonLeft   = int.Parse(backgroundMusicButtonLeft.Text);
            cfg.backgroundMusicButtonTop    = int.Parse(backgroundMusicButtonTop.Text);


            StorageFile storageFile = (StorageFile)backgroundMusicUrl.Tag;

            if (storageFile != null && !string.IsNullOrWhiteSpace(backgroundMusicUrl.Text))
            {
                cfg.backgroundMusicId = storageFile.id;
            }
            else
            {
                cfg.backgroundMusicId = 0;
            }

            Canvas       buttonImageCanvas = FrameworkElementUtil.GetChildObject <Canvas>(BackgroundMusicButtonImageWrapPanel, "buttonImageCanvas");
            StorageImage storageImage      = (StorageImage)buttonImageCanvas.Tag;

            if (storageImage != null)
            {
                cfg.backgroundMusicButtonImageId = storageImage.id;
            }
            else
            {
                cfg.backgroundMusicButtonImageId = 0;
            }
            cfgBll.update(cfg);

            //2.更新全局配置
            App.localStorage.cfg = cfg;
            //3.重新加载页面
            mainWindow.reloadWindow();

            Close();
        }
        private async void loadImage(int n)
        {
            int count = turnImage_listbox.Items.Count;

            if (count <= 0)
            {
                return;
            }

            try
            {
                for (int a = 0; a < count; a++)
                {
                    ListBoxItem item = (ListBoxItem)turnImage_listbox.Items[a];
                    //左右,第一个,最后一个,第二个
                    if ((a >= n - 1 && a <= n + 1) || a == 0 || a == count - 1 || (n == count - 1 && a == 1))
                    {
                        if (item.Background == null)
                        {
                            int x = a;
                            if (a == count - 1)
                            {
                                x = 0;
                            }
                            string imgUrl = AppDomain.CurrentDomain.BaseDirectory + list[x].url;
                            Console.WriteLine(n + "__" + a);
                            Border border = FrameworkElementUtil.GetChildObject <Border>(item, "Loading");
                            if (border != null)
                            {
                                border.Visibility = Visibility.Visible;
                            }

                            ImageSource source = await Task.Run <ImageSource>(() =>
                            {
                                BitmapImage bitmapImage = new BitmapImage();
                                //打开文件流
                                // using (Stream stream = File.OpenRead(imgUrl))
                                using (Stream stream = new MemoryStream(File.ReadAllBytes(imgUrl)))
                                {
                                    bitmapImage.BeginInit();
                                    bitmapImage.CacheOption      = BitmapCacheOption.OnLoad;
                                    bitmapImage.StreamSource     = stream;
                                    bitmapImage.DecodePixelWidth = currDControl.width;
                                    bitmapImage.EndInit();
                                    //这一句很重要,少了UI线程就不认了。
                                    bitmapImage.Freeze();
                                }
                                return(bitmapImage);
                            });

                            //出炉
                            item.Background = new ImageBrush
                            {
                                ImageSource = source
                                ,
                                Stretch = Stretch.Fill
                            };
                            if (border != null)
                            {
                                border.Visibility = Visibility.Hidden;
                            }
                        }
                    }
                    else
                    {
                        item.Background = null;
                        Console.WriteLine("清空" + n + "__" + a);
                    }
                }


                // bigImage.Source = source;
            }
            catch { }
            GC.Collect();
        }