I have some code in place currently to intercept all Cut, Copy and Paste events into a RichTextBox in WPF. These are designed to strip all content out except plain text, and allow no pasting except plain text (by using a check the Clipboard.ContainsText() method.) This seems to be successful at preventing all such operations from inside the forms. A user can only copy, cut and paste text around, with images / audio data / random junk not being allowed.
However, if I use the PrintScreen function, and paste it into one of the RichTextBoxes, the image is pasted in (not the wanted behaviour.) If you then try and paste this image from one RichTextBox to another though, it won't let you (the desired behaviour).
The commands I'm currently overriding are done using
// Command handlers for Cut, Copy and Paste commands.
// To enforce that data can be copied or pasted from the clipboard in text format only.
CommandManager.RegisterClassCommandBinding(typeof(MyRichTextBox),
new CommandBinding(ApplicationCommands.Copy, new ExecutedRoutedEventHandler(OnCopy),
new CanExecuteRoutedEventHandler(OnCanExecuteCopy)));
CommandManager.RegisterClassCommandBinding(typeof(MyRichTextBox),
new CommandBinding(ApplicationCommands.Paste, new ExecutedRoutedEventHandler(OnPaste),
new CanExecuteRoutedEventHandler(OnCanExecutePaste)));
CommandManager.RegisterClassCommandBinding(typeof(MyRichTextBox),
new CommandBinding(ApplicationCommands.Cut, new ExecutedRoutedEventHandler(OnCut),
new CanExecuteRoutedEventHandler(OnCanExecuteCut)));
The OnCopy (etc) methods then essentially check that only text is present before allowing any operations.
There seems to be two Clipboards at work here, one of which I'm not restricting / locking down. Does anyone know of the technicalities of this, and any way in which all Clipboard activity (both Form and System) can be locked down and customized effectively?
Thanks in advance.