private ToggleButton AddToColumnStackPanel(Layer layer)
        {

            var btn = new ToggleButton
            {
                Style = (Style)PART_MasterGrid.FindResource("SideButtonStyle"),
                Width = 20,
                Height = double.NaN,
                Content = layer.Name
            };
            //点击侧边栏按钮触发的事件
            btn.Click += (o, e) =>
            {

                ToggleButton t = e.OriginalSource as ToggleButton;
                {
                    var level = layer.Level;
                    var item = _columnLayers[level];
                    if (t.IsChecked.Value)
                    {
                        item.Grid.Visibility = Visibility.Visible;
                        Grid.SetZIndex(item.Grid, 1);
                        for (int i = 1; i < _columnLayers.Count; i++)
                        {
                            if (i == level)
                                continue;
                            var loc = _columnLayers[i];
                            //这句话就是控制,当前选中项显示在最外层,不会被覆盖掉。
                            Grid.SetZIndex(loc.Grid, 0);
                            if (loc.Btn.Visibility == Visibility.Visible)
                            {
                                loc.Btn.IsChecked = false;
                                loc.Grid.Visibility = Visibility.Collapsed;
                            }

                        }
                    }
                    else
                    {
                        item.Grid.Visibility = Visibility.Collapsed;
                    }
                }

            };
            if (layer.ColumnLocation == Layer.LayerColumnLocation.Right)
                PART_RightCntl.Children.Add(btn);
            else
                PART_LeftCntl.Children.Add(btn);
            return btn;
        }
        private ToggleButton AddToRowStackPanel(Layer layer)
        {
            var btn = new ToggleButton
            {
                Style = (Style)PART_MasterGrid.FindResource("SideButtonStyle"),
                Content = layer.Name
            };
            btn.Click += (o, e) =>
            {
                var level = layer.Level;
                var item = _rowLayers[level];
                item.Grid.Visibility = Visibility.Visible;
                Grid.SetZIndex(item.Grid, 1);
                for (int i = 1; i < _rowLayers.Count; i++)
                {
                    if (i == level)
                        continue;
                    var loc = _rowLayers[i];
                    Grid.SetZIndex(loc.Grid, 0);
                    if (loc.Btn.Visibility == Visibility.Visible)
                        loc.Grid.Visibility = Visibility.Collapsed;

                }

            };
            PART_BottomCntl.Children.Add(btn);
            return btn;
        }
        private void SetupColumnLayers(Grid parentGrid, Layer layer, int columnLayerCnt)
        {
            var grid = new Grid
            {
                Name = ColumnStr + LayerStr + layer.Level,
                Visibility = Visibility.Collapsed
            };
            grid.ColumnDefinitions.Add(new ColumnDefinition
            {
                SharedSizeGroup = layer.ColumnLocation == Layer.LayerColumnLocation.Left
                                                                            ? ColumnStr + layer.Level + layer.ColumnLocation
                                                                            : null,
                Width = GridLength.Auto
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition
            {
                Width = new GridLength(1, GridUnitType.Star)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition
            {
                SharedSizeGroup = layer.ColumnLocation == Layer.LayerColumnLocation.Right
                                                                            ? ColumnStr + layer.Level + layer.ColumnLocation
                                                                            : null,
                Width = GridLength.Auto
            });
            var internalGrid = new Grid();
            internalGrid.RowDefinitions.Add(new RowDefinition
            {
                Height = GridLength.Auto
            });
            internalGrid.RowDefinitions.Add(new RowDefinition());
            //internalGrid.Background = (RadialGradientBrush)PART_MasterGrid.FindResource("myColorfulLabelBrush");
            internalGrid.Background = Brushes.Bisque;

            grid.Children.Add(internalGrid);
            Grid.SetColumn(internalGrid,
                           layer.ColumnLocation == Layer.LayerColumnLocation.Left ? 0 : 2
                          );
            var dockpanel = new DockPanel();
            internalGrid.Children.Add(dockpanel);
            Grid.SetRow(dockpanel, 0);
            var btn = new Button
            {
                Name = ColumnStr + PinStr + layer.Level,
                Width = 28.0,
                Background = Brushes.Transparent,
                BorderBrush = Brushes.Transparent,
                //Style = (Style)PART_MasterGrid.FindResource("buttonStyle"),
                LayoutTransform = new RotateTransform(90),
                Content = new Path
                {
                    Stroke = Brushes.Black,
                    Fill = Brushes.Gold,
                    StrokeThickness = 1,
                    Stretch = Stretch.Fill,
                    Width = 9.0,
                    Height = 15,
                    Data = PinPathgeometry()
                }

            };
            dockpanel.Children.Add(btn);
            DockPanel.SetDock(btn, Dock.Right);
            btn.Click += (o, e) =>
            {
                var level = layer.Level;
                var item = _columnLayers[level].Btn;
                if (item.Visibility == Visibility.Collapsed)
                    ColumnUndockPane(level, o as Button);
                else
                    ColumnDockPane(level, o as Button);


            };
            var textblock = new TextBlock
            {
                Padding = new Thickness(8),
                TextTrimming = TextTrimming.CharacterEllipsis,
                Foreground = Brushes.Black,
                Text = layer.Name
            };
            dockpanel.Children.Add(textblock);
            DockPanel.SetDock(textblock, Dock.Left);
            if (layer.Content != null)
            {
                internalGrid.Children.Add(layer.Content);
                Grid.SetRow(layer.Content, 1);
            }
            var gridSplitter = new GridSplitter
            {
                Width = 2,
                Background = Brushes.CadetBlue,
                HorizontalAlignment = layer.ColumnLocation == Layer.LayerColumnLocation.Right
                                                                            ? HorizontalAlignment.Left
                                                                            : HorizontalAlignment.Right
            };
            grid.Children.Add(gridSplitter);
            Grid.SetColumn(gridSplitter,
                           layer.ColumnLocation == Layer.LayerColumnLocation.Right ? 2 : 0
                          );
            //grid.MouseEnter += (o, e) =>
            //{
            //    var level = layer.Level;
            //    _columnLayers[level].Btn.IsChecked = false;
            //    for (var i = (level + 1); i < _columnLayers.Count; i++)
            //    {
            //        if (_columnLayers[i].Btn.Visibility == Visibility.Visible)
            //        {
            //            _columnLayers[i].Grid.Visibility = Visibility.Collapsed;
            //        }
            //    }
            //};
            parentGrid.Children.Add(grid);
            Grid.SetRow(grid, 0);
            var gnb = new GridnFloatingBtnCombo(grid,
                                                 AddToColumnStackPanel(layer)
                                               );
            if (columnLayerCnt > 0)
            {
                for (var i = layer.Level; i < columnLayerCnt; i++)
                {
                    gnb.ColumnDefinitions.Add(new ColumnDefinition
                    {
                        SharedSizeGroup = ColumnStr + (i + 1) + layer.ColumnLocation,
                        Width = GridLength.Auto
                    });
                    gnb.ColumnLocations.Add(layer.ColumnLocation);
                }
            }
            _columnLayers.Add(gnb);

        }
        private void SetupRowLayers(Grid parentGrid, Layer layer, int numberofRows)
        {
            var grid = new Grid
            {
                Name = RowStr + LayerStr + layer.Level,
                Visibility = Visibility.Collapsed
            };

            grid.RowDefinitions.Add(new RowDefinition
            {
                Height = new GridLength(1, GridUnitType.Star)
            });
            grid.RowDefinitions.Add(new RowDefinition
            {
                SharedSizeGroup = RowStr + layer.Level,
                Height = GridLength.Auto
            });
            //set up dock panel
            var dockpanel = new DockPanel
            {
                Margin = new Thickness(0, 4, 0, 0),
                //Background = (RadialGradientBrush)PART_MasterGrid.FindResource("myColorfulLabelBrush"),
                Background = Brushes.BlueViolet,
                LastChildFill = true
            };
            grid.Children.Add(dockpanel);
            Grid.SetRow(dockpanel, 1);
            var gridsplitter = new GridSplitter
            {
                Height = 4,
                Background = Brushes.CadetBlue,
                ResizeDirection = GridResizeDirection.Rows,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Top
            };
            grid.Children.Add(gridsplitter);
            Grid.SetRow(gridsplitter, 1);
            //set up stackpanel
            //侧边栏按钮控件
            var stackpanel = new StackPanel
            {
                Height = 25.0,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };
            dockpanel.Children.Add(stackpanel);
            DockPanel.SetDock(stackpanel, Dock.Top);
            //set up btn
            var btn = new Button
            {
                Name = RowStr + PinStr + layer.Level,
                Width = 26.0,
                HorizontalAlignment = HorizontalAlignment.Right,
                Background = Brushes.Transparent,
                BorderBrush = Brushes.Transparent,
                // Style = (Style)PART_MasterGrid.FindResource("buttonStyle"),
                BorderThickness = new Thickness(0),
                LayoutTransform = new RotateTransform(90)
            };
            stackpanel.Children.Add(btn);
            var path = new Path
            {
                Stroke = Brushes.Black,
                Fill = Brushes.Gold,
                StrokeThickness = 1,
                Stretch = Stretch.Fill,
                Width = 9.0,
                Height = 15
            };
            var pathgeometry = PinPathgeometry();
            path.Data = pathgeometry;
            btn.Content = path;
            btn.Click += (o, e) =>
            {
                int level = layer.Level;
                var pgrid = parentGrid;
                var item = _rowLayers[level].Btn;
                if (item.Visibility == Visibility.Collapsed)
                    RowUndockPane(level, o as Button, pgrid);
                else
                    RowDockPane(level, o as Button, pgrid);
            };

            if (layer.Content != null)
            {
                dockpanel.Children.Add(layer.Content);
                DockPanel.SetDock(layer.Content, Dock.Top);
            }


            //grid.MouseEnter += (o, e) =>
            //{
            //    var level = layer.Level;
            //    for (var i = 1; i < _rowLayers.Count; i++)
            //    {
            //        if (i == level)
            //            continue;
            //        if (_rowLayers[i].Btn.Visibility == Visibility.Visible)
            //        {
            //            _rowLayers[i].Grid.Visibility = Visibility.Collapsed;
            //        }
            //    }
            //};
            PART_MasterGrid.Children.Add(grid);
            Grid.SetRow(grid, 0);
            var gnb = new GridnFloatingBtnCombo(grid, AddToRowStackPanel(layer));
            if (numberofRows > 0)
            {
                for (int i = layer.Level; i < numberofRows; i++)
                {
                    gnb.RowDefinitions.Add(new RowDefinition
                    {
                        SharedSizeGroup = RowStr + (i + 1),
                        Height = GridLength.Auto
                    });
                }
            }
            _rowLayers.Add(gnb);
        }
        private Grid SetupLayer0(Layer layer0, IEnumerable<Layer> columnLayers, int numberofRows)
        {
            var grid = new Grid { Name = ColumnStr + LayerStr + layer0.Level };
            grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
            grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            if (layer0.Content != null)
                grid.Children.Add(layer0.Content);
            if (layer0.Content != null)
                //layer0排在第二列
                Grid.SetColumn(layer0.Content, 1);
            //根据ToggleButton的Visible属性来实现是否钉住
            grid.MouseLeftButtonDown += (o, e) =>
            {
                for (var i = 1; i < _columnLayers.Count; i++)
                {
                    if (_columnLayers[i].Btn.Visibility == Visibility.Visible)
                    {
                        _columnLayers[i].Grid.Visibility = Visibility.Collapsed;
                        _columnLayers[i].Btn.IsChecked = false;
                    }
                }

                for (var i = 1; i < _rowLayers.Count; i++)
                {
                    if (_rowLayers[i].Btn.Visibility == Visibility.Visible)
                    {
                        _rowLayers[i].Grid.Visibility = Visibility.Collapsed;
                    }
                }
            };
            //显示的控件,主控件不需要侧边按钮
            var gnb = new GridnFloatingBtnCombo(grid, null);
            if (columnLayers.Any())
            {
                var list = columnLayers.ToList();
                for (int i = 0; i < columnLayers.Count(); i++)
                {
                    gnb.ColumnDefinitions.Add(new ColumnDefinition { SharedSizeGroup = ColumnStr + (i + 1) + list[i].ColumnLocation, Width = GridLength.Auto });
                    gnb.ColumnLocations.Add(list[i].ColumnLocation);
                }
            }
            if (numberofRows > 0)
            {
                for (int i = 0; i < numberofRows; i++)
                {
                    gnb.RowDefinitions.Add(new RowDefinition { SharedSizeGroup = RowStr + (i + 1), Height = GridLength.Auto });
                }
            }
            _columnLayers.Add(gnb);
            _rowLayers.Add(gnb);
            return grid;
        }