How can I handle the Paste event for a RichTextBox control in Silverlight 4? (I want to be able to copy-paste images - the Clipboard in SL4 supports only text, so I'm sending the ImageSource Uri, and on the Paste event I want to load the image in the RichTextBox instead of the Uri string).
A:
You can handle the Silverlight 4 clipboard events and then check if focus on the RichTextBox and then simply add the content as a paragraph or other such elements. Have a quick search for Silverlight 4+Clipboard on Google for some good examples.
You would need to handle checking the format of the clipboard text in your handler and then converting if necessary (e.g. plain text, text copied from another RichTextBox, HTML formnatted text etc).
Hope that helps,
Mike Stokes
2010-01-10 21:19:23
A:
public class MyRichTextBox : RichTextBox
{
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.V && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
string text = Clipboard.GetText();
this.Selection.Text = text;
e.Handled = true;
}
else
{
base.OnKeyDown(e);
}
}
...
g.breeze
2010-09-17 20:50:47