Ejemplo n.º 1
0
        protected override bool OnButtonDown(Point pointerPosition)
        {
            this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, (BaseFrameworkElement)null, (IList <BaseFrameworkElement>)null);
            LayoutLineHeaderAdorner lineHeaderAdorner = this.ActiveAdorner as LayoutLineHeaderAdorner;
            LayoutBackgroundAdorner backgroundAdorner = this.ActiveAdorner as LayoutBackgroundAdorner;

            if (lineHeaderAdorner != null)
            {
                GridElement gridElement = (GridElement)lineHeaderAdorner.Element;
                if (lineHeaderAdorner.IsX)
                {
                    GridColumnSelectionSet columnSelectionSet = this.ActiveSceneViewModel.GridColumnSelectionSet;
                    ColumnDefinitionNode   selectionToSet     = gridElement.ColumnDefinitions[lineHeaderAdorner.Index];
                    columnSelectionSet.GridLineMode = true;
                    columnSelectionSet.SetSelection(selectionToSet);
                }
                else
                {
                    GridRowSelectionSet gridRowSelectionSet = this.ActiveSceneViewModel.GridRowSelectionSet;
                    RowDefinitionNode   selectionToSet      = gridElement.RowDefinitions[lineHeaderAdorner.Index];
                    gridRowSelectionSet.GridLineMode = true;
                    gridRowSelectionSet.SetSelection(selectionToSet);
                }
                this.firstLineHeaderDrag = true;
                ((GridRowColumnAdornerSet)lineHeaderAdorner.AdornerSet).DraggingGridline = true;
                return(true);
            }
            return(backgroundAdorner != null);
        }
Ejemplo n.º 2
0
        protected override bool OnClickEnd(Point pointerPosition, int clickCount)
        {
            GridLockAdorner                    gridLockAdorner         = this.ActiveAdorner as GridLockAdorner;
            LayoutBackgroundAdorner            backgroundAdorner       = this.ActiveAdorner as LayoutBackgroundAdorner;
            LayoutLineHeaderAdorner            lineHeaderAdorner       = this.ActiveAdorner as LayoutLineHeaderAdorner;
            GridDesignModeAdorner              designModeAdorner       = this.ActiveAdorner as GridDesignModeAdorner;
            NewGridlineAdorner                 newGridlineAdorner      = this.ActiveAdorner as NewGridlineAdorner;
            LayoutEmptyBackgroundHeaderAdorner backgroundHeaderAdorner = this.ActiveAdorner as LayoutEmptyBackgroundHeaderAdorner;
            GridElement        grid = (GridElement)((Adorner)this.ActiveAdorner).Element;
            GridLayoutDesigner gridLayoutDesigner = (GridLayoutDesigner)grid.LayoutDesigner;

            pointerPosition = this.ToolBehaviorContext.SnappingEngine.SnapPoint(pointerPosition);
            Matrix transformFromRoot = this.ActiveView.GetComputedTransformFromRoot((SceneElement)grid);

            pointerPosition *= transformFromRoot;
            if (backgroundHeaderAdorner == null)
            {
                if (lineHeaderAdorner != null)
                {
                    ((GridRowColumnAdornerSet)lineHeaderAdorner.AdornerSet).DraggingGridline = false;
                    if (clickCount > 1)
                    {
                        if (lineHeaderAdorner.IsX)
                        {
                            gridLayoutDesigner.RemoveColumn(grid, lineHeaderAdorner.Index);
                        }
                        else
                        {
                            gridLayoutDesigner.RemoveRow(grid, lineHeaderAdorner.Index);
                        }
                    }
                }
                else if (gridLockAdorner != null)
                {
                    using (SceneEditTransaction editTransaction = this.ActiveDocument.CreateEditTransaction(StringTable.UndoUnitToggleGridProperty))
                    {
                        if (gridLockAdorner.IsX)
                        {
                            ColumnDefinitionNode columnDefinitionNode = grid.ColumnDefinitions[gridLockAdorner.Index];
                            GridLength           width = columnDefinitionNode.Width;
                            if (width.IsAuto)
                            {
                                columnDefinitionNode.ClearValue(ColumnDefinitionNode.MinWidthProperty);
                                gridLayoutDesigner.SetColumnWidthToStar(grid, gridLockAdorner.Index);
                            }
                            else if (width.IsAbsolute)
                            {
                                gridLayoutDesigner.SetColumnWidth(grid, gridLockAdorner.Index, GridLength.Auto, columnDefinitionNode.ComputedWidth);
                            }
                            else
                            {
                                gridLayoutDesigner.SetColumnWidth(grid, gridLockAdorner.Index, new GridLength(columnDefinitionNode.ComputedWidth), double.NaN);
                            }
                        }
                        else
                        {
                            RowDefinitionNode rowDefinitionNode = grid.RowDefinitions[gridLockAdorner.Index];
                            GridLength        height            = rowDefinitionNode.Height;
                            if (height.IsAuto)
                            {
                                rowDefinitionNode.ClearValue(RowDefinitionNode.MinHeightProperty);
                                gridLayoutDesigner.SetRowHeightToStar(grid, gridLockAdorner.Index);
                            }
                            else if (height.IsAbsolute)
                            {
                                gridLayoutDesigner.SetRowHeight(grid, gridLockAdorner.Index, GridLength.Auto, rowDefinitionNode.ComputedHeight);
                            }
                            else
                            {
                                gridLayoutDesigner.SetRowHeight(grid, gridLockAdorner.Index, new GridLength(rowDefinitionNode.ComputedHeight), double.NaN);
                            }
                        }
                        editTransaction.Commit();
                    }
                }
                else if (backgroundAdorner != null)
                {
                    if (backgroundAdorner.IsX)
                    {
                        GridColumnSelectionSet columnSelectionSet   = this.ActiveSceneViewModel.GridColumnSelectionSet;
                        ColumnDefinitionNode   columnDefinitionNode = grid.ColumnDefinitions[backgroundAdorner.Index];
                        columnSelectionSet.GridLineMode = false;
                        if (this.IsShiftDown)
                        {
                            columnSelectionSet.ToggleSelection(columnDefinitionNode);
                        }
                        else
                        {
                            columnSelectionSet.SetSelection(columnDefinitionNode);
                        }
                    }
                    else
                    {
                        GridRowSelectionSet gridRowSelectionSet = this.ActiveSceneViewModel.GridRowSelectionSet;
                        RowDefinitionNode   rowDefinitionNode   = grid.RowDefinitions[backgroundAdorner.Index];
                        gridRowSelectionSet.GridLineMode = false;
                        if (this.IsShiftDown)
                        {
                            gridRowSelectionSet.ToggleSelection(rowDefinitionNode);
                        }
                        else
                        {
                            gridRowSelectionSet.SetSelection(rowDefinitionNode);
                        }
                    }
                }
                else if (newGridlineAdorner != null && this.IsNewGridlineEnabled)
                {
                    if (newGridlineAdorner.IsX)
                    {
                        gridLayoutDesigner.AddVerticalGridline(grid, pointerPosition.X);
                    }
                    else
                    {
                        gridLayoutDesigner.AddHorizontalGridline(grid, pointerPosition.Y);
                    }
                }
                else if (designModeAdorner != null)
                {
                    grid.ViewModel.IsInGridDesignMode = !designModeAdorner.Grid.ViewModel.IsInGridDesignMode;
                }
            }
            this.ToolBehaviorContext.SnappingEngine.Stop();
            this.ActiveView.UpdateLayout();
            this.ActiveSceneViewModel.RefreshSelection();
            return(base.OnClickEnd(pointerPosition, clickCount));
        }