5 Answers, 1 is accepted
You cannot override the default clipboard commands.
However, you can disable their execution and wire in your implementations of the commands.
You can find an example of how to create a custom command and wire it with RadRichTextBoxRibbonUI in this forum thread. You can also build a custom ContextMenu that executes your commands. For more information on how to do that, you can refer to this article.
Lastly, the clipboard commands can be executed using the keyboard shortcuts (Ctrl + C, Ctrl + V, Ctrl + X).
There is a list of the keyboard shortcuts and the commands they trigger, as well as possible customization options in this article.
I hope this helps.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I have a similar issue. I don't want to override the cut / copy / paste commands, rather I want to trigger another event when the cut command is executed so that I can run some check methods.
Is there a way to raise an event such as Preview Cut?
There is an event CommandExecuting, which is fired when any command is triggered. You can check if the command that has caused the triggering of the event is Cut and interrupt its execution if some criteria are matched:
private
void
editor_CommandExecuting(
object
sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
if
(e.Command
is
CutCommand && shouldInterrupt)
{
e.Cancel =
true
;
}
}
For simplicity, I have used a hypothetical shouldInterrupt boolean field. You can either use a field or perform some checks in the handler of the event.
I hope this helps.
Kind regards,
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I just needed to assign the event like so:
this
.editor.CommandExecuting += editor_CommandExecuting;
One last question. How do I access the clipboard data? What I want to do is loop through the clipboard data before it is pasted to check if it contains any annotations with specific property values.
I can obviously capture the event like so:
if
(e.Command
is
PasteCommand)
{
}
Thanks again for your time and help.
All the best,
Rob
You can use this code snippet to get the document fragment from the clipboard:
if
(e.Command
is
PasteCommand)
{
DocumentFragment fragment = ClipboardEx.GetDocument();
if
(fragment !=
null
)
{
// loop through clipboard data
}
}
DocumentFragment has mostly the same structure of a RadDocument and you can use the EnumerateChildrenOfType<YourAnnotationRangeStart>() method to get all annotation starts and check their properties.
I hope this helps.
Kind regards,
Nikolay Demirev
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.