private async void HomeButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            //如果操作次数大于2,显示消息框,否则直接退回
            //   if (App.Model.Refresh>2)
            await HomeContentDialog.ShowAsync();

            //    else
            //        Frame.GoBack();
        }
        //康戳键
        private void KeyCtrl(VirtualKey value)
        {
            switch (value)
            {
            //Undo:撤销
            case VirtualKey.Z: if (App.Model.isUndo)
                {
                    Undo();
                }
                break;

            case VirtualKey.Y: if (App.Model.isRedo)
                {
                    Redo();
                }
                break;

            case VirtualKey.S:  HomeContentDialog.ShowAsync();  break;

            //Mask:选区
            case VirtualKey.X: 修图.Control.MaskButton.Cut(); break;

            case VirtualKey.C: 修图.Control.MaskButton.Copy(); break;

            case VirtualKey.V:
                DataPackageView dataPackageView = Clipboard.GetContent();
                if (dataPackageView.Contains(StandardDataFormats.Bitmap))
                {
                    IRandomAccessStreamReference imageReceived = null;
                    imageReceived = dataPackageView.GetBitmapAsync().AsTask().Result;
                    if (imageReceived != null)
                    {
                        using (IRandomAccessStream stream = imageReceived.OpenReadAsync().AsTask().Result)
                        {
                            App.Model.SecondCanvasBitmap = CanvasVirtualBitmap.LoadAsync(App.Model.VirtualControl, stream).AsTask().Result;
                            App.InitializeOther();
                            LayerControl_Layers();
                        }
                    }
                }
                else if (App.Model.isClipboard == true)
                {
                    App.InitializeEffect();
                    MaskButton_Mask(102);
                }

                break;

            case VirtualKey.Delete: 修图.Control.MaskButton.Clear(); break;

            case VirtualKey.E: 修图.Control.MaskButton.Extract(); break;

            case VirtualKey.M: 修图.Control.MaskButton.Merge(); break;

            case VirtualKey.A: 修图.Control.MaskButton.All(); break;

            case VirtualKey.D: 修图.Control.MaskButton.Deselect(); break;

            case VirtualKey.P: 修图.Control.MaskButton.Pixel(); break;

            case VirtualKey.I: 修图.Control.MaskButton.Invert(); break;

            case VirtualKey.F: MaskButton_Mask(110); break;

            case VirtualKey.T: MaskButton_Mask(111); break;
            }
        }
 private void HomeContentDialog_CloseButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     HomeContentDialog.Hide();
 }
 private void HomeContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     HomeContentDialog.Hide();
     //Frame.GoBack();
     App.Model.StartVisibility = Visibility.Visible;
 }
        private async void HomeContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            HomeContentDialog.Hide();
            LoadingControl.IsLoading = true;//Con:加载控件
            await Task.Delay(400);

            //1、创建一个XDocument对象
            XDocument    xDoc = new XDocument();
            XDeclaration XDec = new XDeclaration("1.0", "utf-8", "no");

            //设置xml的文档定义
            xDoc.Declaration = XDec;


            //2、创建根节点
            XElement root = new XElement("Layers");

            xDoc.Add(root);

            XElement Width = new XElement("Width", App.Model.Width);

            root.Add(Width);
            XElement Height = new XElement("Height", App.Model.Height);

            root.Add(Height);
            XElement Tool = new XElement("Tool", App.Model.Tool);

            root.Add(Tool);
            XElement Index = new XElement("Index", App.Model.Index);

            root.Add(Index);


            //3、创建主图片
            ICanvasImage ci = App.Model.NullRenderTarget;

            for (int i = App.Model.Layers.Count - 1; i >= 0; i--)  //自下而上渲染
            {
                ci = App.RenderTransform(App.Model.Layers[i], ci); //渲染
            }
            using (CanvasDrawingSession ds = App.Model.SecondBottomRenderTarget.CreateDrawingSession())
            {
                ds.Clear(Color.FromArgb(0, 0, 0, 0));
                ds.DrawImage(ci);
            }
            var      MainBytes        = App.Model.SecondBottomRenderTarget.GetPixelBytes(); //把位图转为byte[]
            var      MainString       = Convert.ToBase64String(MainBytes);                  //把btye[]转为字符串
            XElement MainCanvasRender = new XElement("MainRenderTarget", MainString);       //字符串写入xml节点

            root.Add(MainCanvasRender);


            //4、循环创建节点
            foreach (var l in App.Model.Layers)
            {
                XElement Layer = new XElement("Layer");
                root.Add(Layer);

                //4、创建元素
                XElement LayerName = new XElement("LayerName", l.Name);
                Layer.Add(LayerName);
                XElement LayerVisual = new XElement("LayerVisual", l.Visual);
                Layer.Add(LayerVisual);
                XElement LayerOpacity = new XElement("LayerOpacity", l.Opacity);
                Layer.Add(LayerOpacity);
                XElement LayerBlendIndex = new XElement("LayerBlendIndex", l.BlendIndex);
                Layer.Add(LayerBlendIndex);

                XElement LayerWidth = new XElement("LayerWidth", l.CanvasRenderTarget.SizeInPixels.Width);
                Layer.Add(LayerWidth);
                XElement LayerHeight = new XElement("LayerHeight", l.CanvasRenderTarget.SizeInPixels.Height);
                Layer.Add(LayerHeight);

                var      Bytes = l.CanvasRenderTarget.GetPixelBytes();                 //把位图转为byte[]
                var      str   = Convert.ToBase64String(Bytes);                        //把btye[]转为字符串
                XElement CanvasRenderTarget = new XElement("CanvasRenderTarget", str); //字符串写入xml节点
                Layer.Add(CanvasRenderTarget);
            }


            //5、保存
            string path = ApplicationData.Current.LocalFolder.Path + "/" + App.Model.Name + ".photo"; //将XML文件加载进来

            xDoc.Save(path);


            //6、缩略图 (裁切成宽高最大256的图片)


            //缩略图缩放比例
            float scale = App.Model.Width < App.Model.Height ? 256.0f / App.Model.Width : 256.0f / App.Model.Height;

            //缩放后宽高并确定左右上下偏移
            float W = scale * App.Model.Width;
            float H = scale * App.Model.Height;

            CanvasRenderTarget crt = new CanvasRenderTarget(App.Model.VirtualControl, W, H);

            using (CanvasDrawingSession ds = crt.CreateDrawingSession())
            {
                //绘制缩略图
                ds.DrawImage(new ScaleEffect
                {
                    Source = App.Model.MainRenderTarget,
                    Scale  = new Vector2(scale)
                });
            }
            Library.Image.SavePng(ApplicationData.Current.LocalFolder, crt, App.Model.Name, CreationCollisionOption.ReplaceExisting);

            LoadingControl.IsLoading = false;//Con:加载控件

            // Frame.GoBack();
            App.Model.StartVisibility = Visibility.Visible;
        }