We have a RichTextBox WPF control and since we control the layout, we simply cannot allow any rich content...
Therefor, we need to strip all data except text from the clipboard. For example, if someone is trying to copy/paste lets say text from a table directly from Microsoft Word, the RichTextBox also takes into account that this text was 1. originally from a table, 2. bold and 3. underlined, and create all sorts of inline content to accomodate all these properties of the text...
This is not appropiate behaviour in our case, because it can break our inline layouts.. we just want the clean text...
The most simple approach would be, in the preview paste command:
Clipboard.SetText(Clipboard.GetText());
and be done with it... But you guessed it.. Clipboard operations are not allowed in partial trust...
We also tried a dirty nasty hack, using a hidden Textbox suggested by this link:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5b5bcd71-2eea-4762-bf65-84176c919fce/
Like so:
public static class ClipboardManager
{
private static readonly TextBox textBox = new TextBox {AcceptsReturn = true, AcceptsTab = true};
public static void SetText(string text)
{
textBox.Text = text;
textBox.SelectAll();
textBox.Copy();
}
public static string GetText()
{
textBox.Clear();
textBox.Paste();
return textBox.Text;
}
}
And then call it like this:
ClipboardManager.SetText(ClipboardManager.GetText());
This works well in full trust, but for some reason, both Copy and Paste methods of TextBox do not work in partial trust...
Does anyone know how to retrieve the Clipboard's content in WPF/partial trust ?
Thanks
Edit: As Nir pointed out.. I know it's not very nice to mutate data from your clipboard.. But my question will be answered just the same if someone can just point me out how to retrieve only the text from the clipboard in partial trust :)..