tags:

views:

188

answers:

3

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.

+2  A: 

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.

Josh Einstein
@Josh Thank you very much for your solution. Is there any way to have context menu too?
funwithcoding
A: 

This open source project on Codeplex contains a demo that does just that and much more:

http://sl4popupmenu.codeplex.com/

Ziad
+1  A: 

As Josh has answered, style a TextBox to look like a TextBlock. In terms of copy and paste:

Assuming the users aren't content with just CTRL+C, CTRL+X or CTRL+V - you can now access the clipboard in Silverlight 4:

string content = Clipboard.GetText();
Clipboard.SetText("hello world");

A context menu can be done in various ways, and in Silverlight 4 it is actually properly supported cross browser instead of just IE. You could do it with a Popup or a ChildWindow or just use one from the Vectorlight library:

alt text

Chris S