This is a migrated thread and some comments may be shown as answers.

Pasting as an image

4 Answers 206 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 10 Feb 2017, 01:51 PM

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

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 15 Feb 2017, 11:53 AM
Hello Steven,

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
    }
}
In its handler, you can check if the current command is a PasteCommand and cancel it. Then you can create custom logic for getting the copied information from the clipboard, export it to an image and then import in the RadRichTextBox.

Regards,
Dinko
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Steven
Top achievements
Rank 1
answered on 16 Feb 2017, 10:28 AM
I'll give this a try, thanks.
0
Toan
Top achievements
Rank 1
answered on 30 Sep 2020, 05:02 PM

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.

 

0
Martin
Telerik team
answered on 01 Oct 2020, 01:04 PM

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).

Tags
RichTextBox
Asked by
Steven
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Steven
Top achievements
Rank 1
Toan
Top achievements
Rank 1
Martin
Telerik team
Share this question
or