Copying to Clipboard

I am trying to implement a 2nd copy function, but nothing is being added to the diagram when I paste after using the new copy.

This is what the new method looks like:

<span ="Apple-tab-span" style="white-space:pre">	</span>public void CopyWithData()
            CopiedParts = this.Diagram.SelectedParts.ToList();

            var CopiedDatas = Diagram.Model.CreateDataCollection();

            foreach (Node node in CopiedParts.Where(x => x is Node))

            foreach (Link link in CopiedParts.Where(x => x is Link))

            CopyToClipboard(CopiedDatas);<span style="font-size: 12px; line-height: 1.4;">   </span>

What do I need to change/add to make these objects available for the Paste command?


Are you getting any error/warning messages during this function? I’m wondering if your data has any serialization issues. Oh, and is this WPF or Silverlight?

Why can’t you just call myDiagram.CommandHandler.Copy()?

This is WPF… No errors during the Copy, but I am getting an error during Paste:

System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)
at System.Windows.DataObject.GetData(String format, Boolean autoConvert)
at System.Windows.Clipboard.GetDataInternal(String format)
at System.Windows.Clipboard.GetData(String format)
at Northwoods.GoXam.CommandHandler.PasteFromClipboard()
at Northwoods.GoXam.CommandHandler.Paste()

And I’m not using the regular Copy as that calls Clone for each object data class, but I’ve added another method CopyWithData that I would like to use for this copy. We are still using Copy & Clone, but with those we are clearing out values of the addition properties we’ve added to the class, with this new method we would like to retain the values of all of the properties.

Are all of your objects instances of classes that are [Serializable] or implement ISerializable?

Yes, they are all [Serializable]

Well, it is certainly a common error when I search the web, but it still isn’t clear to me what the cause is if it is not serializability.

Maybe you can try serializing to and deserializing from a stream so that you can debug it.