示例#1
0
        protected override bool OnDragEnd(Point dragStartPosition, Point dragEndPosition)
        {
            LayoutLineHeaderAdorner lineHeaderAdorner  = this.ActiveAdorner as LayoutLineHeaderAdorner;
            NewGridlineAdorner      newGridlineAdorner = this.ActiveAdorner as NewGridlineAdorner;

            if (lineHeaderAdorner != null)
            {
                ((GridRowColumnAdornerSet)lineHeaderAdorner.AdornerSet).DraggingGridline = false;
            }
            else if (newGridlineAdorner != null && this.IsNewGridlineEnabled)
            {
                GridElement        grid = (GridElement)((Adorner)this.ActiveAdorner).Element;
                GridLayoutDesigner gridLayoutDesigner = (GridLayoutDesigner)grid.LayoutDesigner;
                dragEndPosition = this.ToolBehaviorContext.SnappingEngine.SnapPoint(dragEndPosition);
                Matrix transformFromRoot = this.ActiveView.GetComputedTransformFromRoot((SceneElement)grid);
                dragEndPosition *= transformFromRoot;
                if (newGridlineAdorner.IsX)
                {
                    gridLayoutDesigner.AddVerticalGridline(grid, dragEndPosition.X);
                }
                else
                {
                    gridLayoutDesigner.AddHorizontalGridline(grid, dragEndPosition.Y);
                }
            }
            this.ToolBehaviorContext.SnappingEngine.Stop();
            this.CommitEditTransaction();
            return(base.OnDragEnd(dragStartPosition, dragEndPosition));
        }
示例#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));
        }