Search code examples
silverlight

Silverlight 3: How to implement Textblock copy/paste functionality?


Silverlight is awesome, most of my application users are giving positive feedback about silverlight. However some of the users are not able to live without copy/paste functionality. They are very much used to copy/paste functionality provided by HTML page out of the box.

How can I implement such a context menu as well as copy/paste functionality?

PS: Windows only solution is fine too.


Solution

  • Aside from using TextBox with IsReadOnly=true, you'll have a pretty hard time trying to simulate selection and copy/paste in a TextBlock. I would identify the areas they wish to copy/paste the most and use TextBox's there. You could even remove the border and make a transparent background and it should look nearly identical to adjacent TextBlock's.

    If you do that then you will get the selection and copy functionality provided by TextBox and it works across browsers.

    Otherwise you will need to go through the browser's DOM to put stuff on the clipboard and that will be a pain because of cross-browser concerns. Silverlight 4 adds a Clipboard API if you're able to start development with a beta version.