private void AddDefaultstyleToMenu(ContextMenu contextMenu)
        {
            contextMenu.Items.Add(new Separator());
            ContextMenuItem Defaultstyle = new ContextMenuItem(GlobalData.FindResource("ContextMenu_DefaultStyle"),
                                                               SetDefaultStyleCommand);

            contextMenu.Items.Add(Defaultstyle);
        }
        private void AddGridGuide2Menu(ContextMenu contextMenu)
        {
            ContextMenuItem grid = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid"));
            ContextMenuItem item = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_ShowGrid"), CommonDefine.KeyShowGrid, ShowGridCommand);

            item.IsCheckable = true;
            item.IsChecked   = GlobalData.IsShowGrid;
            grid.Items.Add(item);
            item             = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_SnapToGrid"), CommonDefine.KeySnaptoGrid, SnaptoGridCommand);
            item.IsCheckable = true;
            item.IsChecked   = GlobalData.IsSnapToGrid;
            grid.Items.Add(item);

            item = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_GridSet"), GridSettingCommand);
            grid.Items.Add(item);
            grid.Items.Add(new Separator());

            item             = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_ShowGlobalGuid"), CommonDefine.KeyShowGlobalGuide, ShowGlobalGuideCommand);
            item.IsCheckable = true;
            item.IsChecked   = GlobalData.IsShowGlobalGuide;
            grid.Items.Add(item);

            item             = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_ShowPageGuide"), CommonDefine.KeyShowPageGuide, ShowPageGuideCommand);
            item.IsCheckable = true;
            item.IsChecked   = GlobalData.IsShowPageGuide;
            grid.Items.Add(item);

            item             = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_SnapToGuide"), CommonDefine.KeySnaptoGuide, SnaptoGuideCommand);
            item.IsCheckable = true;
            item.IsChecked   = GlobalData.IsSnapToGuide;
            grid.Items.Add(item);

            item             = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_LockGuide"), CommonDefine.KeyLockGuide, LockGuidesCommand);
            item.IsCheckable = true;
            item.IsChecked   = GlobalData.IsLockGuides;
            grid.Items.Add(item);
            item = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_CreateGuide"), CreateGuidesCommand);
            grid.Items.Add(item);

            item = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_DelteAllGuide"), DeleteAllGuidesCommand);
            grid.Items.Add(item);

            item = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_GuideSet"), GuideSetttingCommand);
            grid.Items.Add(item);

            // grid.Items.Add(new Separator());

            //item = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_SnapToObject"), SnaptoObjectCommand);
            //item.IsCheckable = true;
            //item.IsChecked = false;
            //grid.Items.Add(item);
            //item = new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Grid_ObjectSnapSet"), ObjectSnapSettingCommand);
            //grid.Items.Add(item);

            contextMenu.Items.Add(grid);
        }
        private void AddDistribute2Menu(ContextMenu contextMenu)
        {
            ContextMenuItem distribute = new ContextMenuItem(GlobalData.FindResource("ContextMenu_Distribute"));

            distribute.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Distribute_Hor"),
                                                     DistributeHorizCommand, "Distribute_Hor", CommonDefine.KeyDistributeHori));
            distribute.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Distribute_Ver"),
                                                     DistributeVertiCommand, "Distribute_Ver", CommonDefine.KeyDistributeVert));
            contextMenu.Items.Add(distribute);
        }
        private void AddConvertMaster2Menu(ContextMenu contextMenu, bool bSep = true)
        {
            if (_document == null)
            {
                return;
            }


            List <IWidgetPropertyData> wdgs = _selectionService.GetSelectedWidgets();
            bool bCanConvert2Master         = true;

            foreach (WidgetViewModBase it in wdgs)
            {
                if (it is MasterWidgetViewModel)
                {
                    bCanConvert2Master = false;
                    break;
                }
                else if (it is GroupViewModel)
                {
                    GroupViewModel group  = it as GroupViewModel;
                    var            target = group.WidgetChildren.FirstOrDefault(a => a is MasterWidgetViewModel);
                    if (target != null)
                    {
                        bCanConvert2Master = false;
                        break;
                    }
                }
                else
                {
                    if (it.RealParentGroupGID != Guid.Empty)
                    {
                        bCanConvert2Master = false;
                        break;
                    }
                }
            }

            if (bCanConvert2Master == false)
            {
                return;
            }


            ContextMenuItem convertToMaster = new ContextMenuItem(GlobalData.FindResource("Master_ContextMenu_ConvertToMaster"), ConvertToMasterCommand, "ConvertMaster", string.Empty);

            contextMenu.Items.Add(convertToMaster);

            if (bSep == true)
            {
                contextMenu.Items.Add(new Separator());
            }
        }
        private void AddOrder2Menu(ContextMenu contextMenu, bool bSep = true)
        {
            if (bSep)
            {
                contextMenu.Items.Add(new Separator());
            }
            ContextMenuItem order = new ContextMenuItem(GlobalData.FindResource("ContextMenu_Order"));

            order.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_BringFront"),
                                                BringFrontCommand, "Bring_Front", CommonDefine.KeyBringFront));
            order.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_SendBack"),
                                                SendBackCommand, "Send_Back", CommonDefine.KeySendBack));
            order.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_BringForward"),
                                                BringForwardCommand, "Bring_Forward", CommonDefine.KeyBringForward));
            order.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_SendBackward"),
                                                SendBackwardCommand, "Send_Backward", CommonDefine.KeySendBackward));
            contextMenu.Items.Add(order);
        }
        private void AddAlignM2Menu(ContextMenu contextMenu)
        {
            ContextMenuItem align = new ContextMenuItem(GlobalData.FindResource("ContextMenu_Align"));

            align.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Align_Left"),
                                                AlignLeftCommand, "Align_Left", CommonDefine.KeyAlignLeft));
            align.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Align_Center"),
                                                AlignCenterCommand, "Align_Center", CommonDefine.KeyAlignCenter));
            align.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Align_Right"),
                                                AlignRightCommand, "Align_Right", CommonDefine.KeyAlignRight));
            align.Items.Add(new Separator());
            align.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Align_Top"),
                                                AlignTopCommand, "Align_Top", CommonDefine.KeyAlignTop));
            align.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Align_Middle"),
                                                AlignMiddleCommand, "Align_Middle", CommonDefine.KeyAlignMiddle));
            align.Items.Add(new ContextMenuItem(GlobalData.FindResource("Menu_Arrange_Align_Bottom"),
                                                AlignBottomCommand, "Align_Bottom", CommonDefine.KeyAlignBottom));
            contextMenu.Items.Add(align);
        }
        private void AddMasterOperationMenu(ContextMenu contextMenu, bool bIsLocationLock = false, bool isGroupChild = false)
        {
            //TODO:Master Break Away
            ContextMenuItem item2 = new ContextMenuItem(GlobalData.FindResource("Master_ContextMenu_BreakAway"), MasterBreakAwayCommand);

            if (isGroupChild == true)
            {
                item2.IsEnabled = false;
            }
            contextMenu.Items.Add(item2);

            //TODO:Master Lock to location
            ContextMenuItem item = new ContextMenuItem(GlobalData.FindResource("Master_ContextMenu_LocktoMasterLocation"), MasterLock2LocationCommand);

            item.IsCheckable = true;
            item.IsChecked   = bIsLocationLock;
            contextMenu.Items.Add(item);

            //Add Separator;
            contextMenu.Items.Add(new Separator());
        }
        private void AddExport2Menu(ContextMenu contextMenu, bool bSep = true)
        {
            string menuHeader;

            if (0 == _selectionService.WidgetNumber)
            {
                menuHeader = GlobalData.FindResource("ContextMenu_ExportPage2Image");
            }
            else
            {
                menuHeader = GlobalData.FindResource("ContextMenu_ExportObject2Image");
            }
            ContextMenuItem item = new ContextMenuItem(menuHeader, ExportToImageCommand);

            contextMenu.Items.Add(item);

            if (bSep == true)
            {
                contextMenu.Items.Add(new Separator());
            }
        }
        /// <summary>
        /// Create menu when select nothing.
        /// </summary>
        private void MenuFor0Widget()
        {
            ContextMenu contextMenu = new ContextMenu();

            contextMenu.IsOpen = true;
            ContextMenuItem item = new ContextMenuItem(GlobalData.FindResource("Menu_File_Paste"),
                                                       PasteCommand, "Paste", CommonDefine.KeyPaste);

            contextMenu.Items.Add(item);
            contextMenu.Items.Add(new ContextMenuItem(GlobalData.FindResource("ContextMenu_SelectAll"), CommonDefine.KeySelectAll, SelectAllCommand));

            AddExport2Menu(contextMenu);

            AddGridGuide2Menu(contextMenu);


            //code to extract menu template
            //var str = new StringBuilder();
            //using (var writer = new StringWriter(str))
            //    XamlWriter.Save(item.Template, writer);
            //Debug.Write(str);
        }
        private void AddLibrary2Menu(ContextMenu contextMenu)
        {
            if (_document == null)
            {
                return;
            }

            ContextMenuItem addToLibrary = new ContextMenuItem(GlobalData.FindResource("ContextMenu_AddToLibrary"));

            addToLibrary.Style = Application.Current.TryFindResource("librarymenu") as Style;

            ICustomLibraryService customLibraryService = ServiceLocator.Current.GetInstance <ICustomLibraryService>();

            foreach (ICustomLibrary item in customLibraryService.GetAllCustomLibraies())
            {
                //don't add current library to library list.
                if (_document.DocumentType == DocumentType.Library && item.LibraryGID == _document.Guid)
                {
                    continue;
                }

                string itemHeader = item.Header;
                if (item.TabType != null && item.Header.StartsWith(item.TabType))
                {
                    itemHeader = item.Header.Substring(item.TabType.Length);
                }

                addToLibrary.Items.Add(new ContextMenuItem(itemHeader, AddToLibraryCommand, item));
                addToLibrary.Tag = "limit";
            }
            addToLibrary.Items.Add(new ContextMenuItem(GlobalData.FindResource("ContextMenu_AddLibrary"), AddLibraryCommand));
            contextMenu.Items.Add(addToLibrary);

            contextMenu.Items.Add(new ContextMenuItem(GlobalData.FindResource("ContextMenu_ExportToLibrary"), ExportToLibraryCommand));

            contextMenu.Items.Add(new Separator());
        }