Пример #1
0
        public Rect PasteSelectedStrokes(Point position)
        {
            var rect = Rect.Empty;

            if (CanPaste)
            {
                var ids = GetStrokes().Select(s => s.Id).ToList();

                rect = _strokeContainer.PasteFromClipboard(position);

                var pastedStrokes = _strokeContainer.GetStrokes().Where(s => !ids.Contains(s.Id));

                PasteStrokesEvent?.Invoke(this, new CopyPasteStrokesEventArgs(pastedStrokes));
            }

            return(rect);
        }
        private void OnInkToolbarAction(object sender, RoutedEventArgs e)
        {
            string option = (sender as Button).Name;

            switch (option)
            {
            case "Copy":
            case "Cut":
                this.copyContainer = new InkStrokeContainer();
                if (this.renderedStrokes.Any())
                {
                    foreach (InkStroke stroke in this.renderedStrokes.Where(s => s.Selected))
                    {
                        this.copyContainer.AddStroke(stroke.Clone());
                    }

                    this.copyContainer.SelectWithPolyLine(this.lasso.Points);
                    this.copyContainer.CopySelectedToClipboard();
                    if (option == "Cut")
                    {
                        this.OnEraserClicked(sender, null);
                    }

                    this.canvas.Invalidate();
                }
                break;

            case "Paste":
                //Unselects all previously selected areas
                foreach (InkStrokeContainer container in this.strokes)
                {
                    container.SelectWithLine(new Point(0, 0), new Point(0, 0));
                }

                //Fake paste to determine pasted content size
                InkStrokeContainer pasteFakeContainer = new InkStrokeContainer();
                Rect pastedContentArea = pasteFakeContainer.PasteFromClipboard(this.toolbarPosition);

                //Paste it ensuring it fits client size
                InkStrokeContainer pasteContainer = new InkStrokeContainer();
                Point pastePoint         = this.EnsureFit(this.toolbarPosition, pastedContentArea);
                Rect  pastedBoundingRect = pasteContainer.PasteFromClipboard(pastePoint);
                this.DrawBoundingRect(pastedBoundingRect);

                //Selects pasted ink
                List <Point> pastedLasso = new List <Point>();
                pastedLasso.Add(new Point(pastedBoundingRect.X, pastedBoundingRect.Y));
                pastedLasso.Add(new Point(pastedBoundingRect.X + pastedBoundingRect.Width, pastedBoundingRect.Y));
                pastedLasso.Add(new Point(pastedBoundingRect.X + pastedBoundingRect.Width, pastedBoundingRect.Y + pastedBoundingRect.Height));
                pastedLasso.Add(new Point(pastedBoundingRect.X, pastedBoundingRect.Y + pastedBoundingRect.Height));
                pastedLasso.Add(new Point(pastedBoundingRect.X, pastedBoundingRect.Y));
                pasteContainer.SelectWithPolyLine(pastedLasso);
                this.strokes.Add(pasteContainer);
                this.canvas.Invalidate();
                //Se lasso matching pasted content
                this.lasso = new Polyline()
                {
                    Stroke          = new SolidColorBrush(Colors.Blue),
                    StrokeThickness = 1,
                    StrokeDashArray = new DoubleCollection()
                    {
                        5, 2
                    },
                };
                foreach (Point lassoPoint in pastedLasso)
                {
                    this.lasso.Points.Add(lassoPoint);
                }
                //We move into lasso mode to let user move pasted selection
                //this.OnLassoChecked(this,null);
                this.hasPasted = true;
                break;

            case "Delete":
                this.OnEraserClicked(sender, null);
                break;
            }

            this.InkSelectionToolbar.Visibility = Visibility.Collapsed;
        }