// Token: 0x06006D0E RID: 27918 RVA: 0x001F5420 File Offset: 0x001F3620
        internal bool PasteData(IDataObject dataObject, ref StrokeCollection newStrokes, ref List <UIElement> newElements)
        {
            foreach (KeyValuePair <InkCanvasClipboardFormat, ClipboardData> keyValuePair in this._preferredClipboardData)
            {
                InkCanvasClipboardFormat key   = keyValuePair.Key;
                ClipboardData            value = keyValuePair.Value;
                if (value.CanPaste(dataObject))
                {
                    switch (key)
                    {
                    case InkCanvasClipboardFormat.InkSerializedFormat:
                    {
                        ISFClipboardData isfclipboardData = (ISFClipboardData)value;
                        isfclipboardData.PasteFromDataObject(dataObject);
                        newStrokes = isfclipboardData.Strokes;
                        break;
                    }

                    case InkCanvasClipboardFormat.Text:
                    {
                        TextClipboardData textClipboardData = (TextClipboardData)value;
                        textClipboardData.PasteFromDataObject(dataObject);
                        newElements = textClipboardData.Elements;
                        break;
                    }

                    case InkCanvasClipboardFormat.Xaml:
                    {
                        XamlClipboardData xamlClipboardData = (XamlClipboardData)value;
                        xamlClipboardData.PasteFromDataObject(dataObject);
                        List <UIElement> elements = xamlClipboardData.Elements;
                        if (elements != null && elements.Count != 0)
                        {
                            if (elements.Count == 1 && ClipboardProcessor.InkCanvasDType.IsInstanceOfType(elements[0]))
                            {
                                this.TearDownInkCanvasContainer((InkCanvas)elements[0], ref newStrokes, ref newElements);
                            }
                            else
                            {
                                newElements = elements;
                            }
                        }
                        break;
                    }
                    }
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// The method returns the Strokes or UIElement array if there is the supported data in the IDataObject
        /// </summary>
        /// <param name="dataObject">The IDataObject instance</param>
        /// <param name="newStrokes">The strokes which are converted from the data in the IDataObject</param>
        /// <param name="newElements">The elements array which are converted from the data in the IDataObject</param>
        internal bool PasteData(IDataObject dataObject, ref StrokeCollection newStrokes, ref List <UIElement> newElements)
        {
            Debug.Assert(dataObject != null && _preferredClipboardData != null);

            // We honor the order in our preferred list.
            foreach (KeyValuePair <InkCanvasClipboardFormat, ClipboardData> pair in _preferredClipboardData)
            {
                InkCanvasClipboardFormat format = pair.Key;
                ClipboardData            data   = pair.Value;

                if (data.CanPaste(dataObject))
                {
                    switch (format)
                    {
                    case InkCanvasClipboardFormat.Xaml:
                    {
                        XamlClipboardData xamlData = (XamlClipboardData)data;
                        xamlData.PasteFromDataObject(dataObject);

                        List <UIElement> elements = xamlData.Elements;

                        if (elements != null && elements.Count != 0)
                        {
                            // If the Xaml data has been set in an InkCanvas, the top element will be a container InkCanvas.
                            // In this case, the new elements will be the children of the container.
                            // Otherwise, the new elements will be whatever data from the data object.
                            if (elements.Count == 1 && ClipboardProcessor.InkCanvasDType.IsInstanceOfType(elements[0]))
                            {
                                TearDownInkCanvasContainer((InkCanvas)(elements[0]), ref newStrokes, ref newElements);
                            }
                            else
                            {
                                // The new elements are the data in the data object.
                                newElements = elements;
                            }
                        }
                        break;
                    }

                    case InkCanvasClipboardFormat.InkSerializedFormat:
                    {
                        // Retrieve the stroke data.
                        ISFClipboardData isfData = (ISFClipboardData)data;
                        isfData.PasteFromDataObject(dataObject);

                        newStrokes = isfData.Strokes;
                        break;
                    }

                    case InkCanvasClipboardFormat.Text:
                    {
                        // Convert the text data in the data object to a text box element.
                        TextClipboardData textData = (TextClipboardData)data;
                        textData.PasteFromDataObject(dataObject);
                        newElements = textData.Elements;
                        break;
                    }
                    }

                    // Once we've done pasting, just return now.
                    return(true);
                }
            }

            // Nothing gets pasted.
            return(false);
        }