Hi,
Is it possible to paste some copied data into a RichTextBox as an image like you can in Outlook?
We have a table in excel that we would like to paste in so it is an image in the RichTextBox rather than an editable table.
I have had a look around the forum and the docs but I can't see anything.
Thanks,
Steve
4 Answers, 1 is accepted
Currently, this feature is not supported from the RadRichTextBox out of the box. An approach which we could suggest you is to subscribe to the CommandExecuting event of the RadRichTextBox control.
private
void
rtb_CommandExecuting(
object
sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
if
(e.Command.GetType().Name ==
"PasteCommand"
)
{
e.Cancel =
true
;
// Your custom logic
}
}
Regards,
Dinko
Telerik by Progress
Hi Dinko,
I am using Telerik WPF 2020 R1. In my RadRichTextBox, when i paste an image using "Keep Text Only" option, i would get Object Reference Not Set error like it is in the Demo app. In my code, I set up CommandExecuting event for RadRickTextBox like you suggested:
<telerik:RadRichTextBox
Grid.Row="1" Name="editor" Margin="0" DocumentInheritsDefaultStyleSettings="False" LayoutMode="Flow"
IsEnabled="{Binding Path=IsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
FontFamily="{Binding Path=DefaultFont, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Mode=TwoWay}"
FontSize="{Binding Path=DefaultFontSize, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Mode=TwoWay}"
HorizontalScrollBarVisibility="Disabled" IsSpellCheckingEnabled="True" VerticalScrollBarVisibility="Auto"
IsReadOnly="{Binding Path=IsReadOnly,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
MouseOverBorderThickness="0" AcceptsTab="False"
CommandExecuting="editor_CommandExecuting" Loaded="editor_opened">
and
<telerik:RadRibbonDropDownButton CollapseToSmall="WhenGroupIsMedium" Size="Medium" telerik:ScreenTip.Description="Paste the contents of the Clipboard."
SmallImage="pack://application:,,,/Telerik.Windows.Controls.RichTextBoxUI;component/Images/MSOffice/16/paste.png"
telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding PasteCommand}" telerik:ScreenTip.Title="Paste" >
<telerik:RadRibbonDropDownButton.DropDownContent>
<telerik:PasteOptionsPicker Owner="{Binding AssociatedRichTextBox}" />
</telerik:RadRibbonDropDownButton.DropDownContent>
</telerik:RadRibbonDropDownButton>
Code behind:
void editor_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
if (e.Command is PasteCommand)
{
...
}
}
What i found is that the editor_CommandExecuting event handler is being triggered AFTER the paste action happens. And i think that's why i get the error. Could you please tell me what i did wrong?
Thank you,
Toan.
Hi Toan,
Thank you for the provided feedback.
I successfully reproduced this behavior. It seems it is caused when trying to delete (skip) an element that has no parent set. I logged an item on your behalf in our backlog to fix this: RichTextBox: NullReferenceException is thrown when pasting a copied image with Keep Text Only paste option. I am afraid I cannot provide you with a workaround, so please, make sure to follow the item so you can receive updates when its status changes.
In appreciation for bringing this to our attention, I updated your Telerik points.
Regards,
Martin
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).