Search code examples
c#wpftuplesclipboard

How to copy Tuples to clipboard


I have to copy three different data to the clipboard. So I create a Tuple and copy it to the clipboard and then I copy it to clipboard

var newTuple = new Tuple<Component, Color?, bool?>(CopyComponent, headerColour_Copied, IsHeaderForegroundDark_Copied);
Clipboard.SetDataObject(newTuple);

when copying I get an exception which translated may sound like "Other data are available". I also tried to purge the clipboard but that was of no help.

Clipboard.SetDataObject(CopyComponent);
Clipboard.SetDataObject(headerColour_Copied);
Clipboard.SetDataObject(IsHeaderForegroundDark_Copied);

Please notice that if I don't make a Tuple but set each datum separately everything is fine.

So can't tuples be copied to clipboard??

I also tried to box each of the three datum into an object without but still fails

Thanks for helping

Patrick


Solution

  • Generic types typically don't play very well outside the realm of . net; try sending a plain array of values instead:

    Clipboard.SetDataObject(new object[] { CopyComponent, headerColour_Copied, IsHeaderForegroundDark_Copied });
    

    Clipboard content can be consumed by any application; basic intrinsic types are a safer bet here.