Example #1
0
        public void CopyInkCanvasObjects(InkCanvas inkCanvas, InkCanvas clipboardCanvas)
        {
            var selectionBounds = inkCanvas.GetSelectionBounds();

            if (selectionBounds.IsEmpty)
            {
                return;
            }
            Clear(clipboardCanvas);

            var selectedElements = inkCanvas.GetSelectedElements().ToList();
            var selectedStrokes  = new StrokeCollection(inkCanvas.GetSelectedStrokes());

            ClearSelection(inkCanvas);

            var elements = new List <UIElement>();

            WPFHelper.CloneElementsTo(elements, selectedElements.GetEnumerator(), clipboardCanvas);
            WPFHelper.CloneStrokesTo(clipboardCanvas.Strokes, selectedStrokes);
            elements.ForEach(element => clipboardCanvas.Children.Add(element));
            inkCanvas.Select(selectedStrokes, selectedElements);

            var dataObject = new DataObject();

            dataObject.SetData(ClipboardIdFormat, _clipboardStateId = Guid.NewGuid());
            dataObject.SetData(DataFormats.Bitmap, ImageHelper.GetCroppedImageFromInkCanvas(selectionBounds, inkCanvas));
            Clipboard.SetDataObject(dataObject);
        }
Example #2
0
        public void Paste(InkCanvas inkCanvas, InkCanvas clipboardCanvas)
        {
            if (!ContainsImage())
            {
                EventBroker.Instance.ActionResult(Resources.Title_Paste, Resources.Message_Clipboard_does_not_contain_any_image_as_expected);
                return;
            }

            if (ClipboardWasChangedOutside())
            {
                var image = ImageHelper.AddImageTo(inkCanvas, new Bitmap(GetImage()));
                ActivateSelectionMode(inkCanvas);
                inkCanvas.Select(new List <UIElement> {
                    image
                });
                return;
            }
            _currentPasteOffset += PasteOffset;
            ClearSelection(inkCanvas);
            var elements = new List <UIElement>();
            var strokes  = new StrokeCollection();

            WPFHelper.CloneElementsTo(elements, clipboardCanvas.Children.GetEnumerator(), inkCanvas, _currentPasteOffset);
            WPFHelper.CloneStrokesTo(strokes, clipboardCanvas.Strokes, _currentPasteOffset);
            elements.ForEach(element => inkCanvas.Children.Add(element));
            inkCanvas.Strokes.Add(strokes);
            ActivateSelectionMode(inkCanvas);
            inkCanvas.Select(strokes, elements);
        }