tags:

views:

31

answers:

1

Can I Store more than 1 type in the Clipboard? Eg. like Text & Image. say the user pastes in a text editor, he gets the text and if he pastes in something like photoshop, he gets the image. I thought it was possible but I tried

Clipboard.Clear();
Clipboard.SetText(img.DirectLink);

BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(img.DirectLink);
bitmapImage.EndInit();

Clipboard.SetImage(bitmapImage);

and I always get the image

+3  A: 

Yes, it is possible. The main problem, methods you are using clears clipboard before put data (that's why in particular they named "Set..." instead of "Add...").

Clipboard.SetText description from MSDN:

Clears the Clipboard and then adds text data in the Text or UnicodeText format, depending on the operating system.

But solution relatively easy:

To place data on the Clipboard in multiple formats, use the DataObject class or an IDataObject implementation. Place data on the Clipboard in multiple formats to maximize the possibility that a target application, whose format requirements you might not know, can successfully retrieve the data.

Check MSDN for details: http://msdn.microsoft.com/en-us/library/25w5tzxb.aspx

Nick Martyshchenko