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

Pasting Plain Text from Clipboard

8 Answers 359 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Thilo
Top achievements
Rank 1
Iron
Thilo asked on 10 Jun 2015, 07:19 AM

We have the Problem, that the Users can't Paste Plain Text from Clipboard (Cut out from our old Delphi Win32 Applikation) in the RichTextBox.

If it is RTF or HTML Text it Works, but not with Plain Text, what we are missing ?

As Workaround the User can Cut the Text out in the old Application, paste it e.g. in an new eMail (HTML) Body, Mark it again to put in Clipboard and then they can Paste it in the RichTextBox, but that can't be the way.

In the section 'Clipboard' in the RichText Documentation stands that first the insert try RTF second HTML and third Text, but this doesn't work.

Can you please help me ?

Greetings

T. Schmitz

8 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 12 Jun 2015, 12:31 PM
Hello Thilo,

As I'm unable to replicate this on our end I couldn't say what might be the cause for it.

Could you try subscribing to the CommandExecuting event of RadRichTextBox and inspect the data in the clipboard? Here is how you can enumerate the clipboard handlers and obtain DocumentFragments with the data in the clipboard.
void radRichTextBox_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        DocumentFragment documentFromClipboard = ClipboardEx.GetDocumentFromClipboard("RadDocumentGUID"); //copy pasting from a RadRichTextBox, keep the paragraphs as they are
        if (documentFromClipboard == null)
        {
            foreach (var handler in ClipboardEx.ClipboardHandlers) //RTF, HTML, TXT
            {
                documentFromClipboard = ClipboardEx.GetDocumentFromClipboard(handler.ClipboardDataFormat, handler.ClipboardStringFilter);
                if (documentFromClipboard != null)
                {
 
                }
            }
        }
    }
}

Please let me know whether there is a fragment in the clipboard for either of those cases. 

Regards,
Petya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Thilo
Top achievements
Rank 1
Iron
answered on 14 Jul 2016, 09:36 AM

Hallo Petya,

it's take a Long time... But lot of work and Users are quiet about this... but

The Problem is not solved.

So i tried your Code with the following result:

the documentFromClipboard is always null when i try to paste plane text.

If i paste from word the documentFromClipboard is not null in case of RTF and HTML but in case of TXT

I extendet the Code with

var isText = Clipboard.ContainsText();

var isUnicodeText = Clipboard.ContainsText(TextDataFormat.UnicodeText);

both bool vars are true in case of Plain Text and Word Text.

so, is there a Problem in ClipboardEx.GetDocumentFromClipboard ?

is it eventuality a Problem with the culture Settings (our Workstations Culture Setting is German)

Thank you for further advice!

0
Petya
Telerik team
answered on 15 Jul 2016, 08:49 AM
Hello Thilo,

I'm not sure I entirely understand the issue that you're facing. If I properly understand you, you are copying content from MS Word and expect to paste it in RadRichTextBox as plain text, is that correct?

Could you share which version of the WPF suite you're using precisely? I tried the scenario, but the fragments for all three clipboard handlers are properly populated when pasting. By default, their priorities enforce to use the RTF handler if the respective assembly is referenced, but I had no issues overriding this in the manner shown in my previous snippet:
void radRichTextBox_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    if (e.Command is PasteCommand)
    {
        var documentFromClipboard = ClipboardEx.GetDocumentFromClipboard("UnicodeText");
        (sender as RadRichTextBox).InsertFragment(documentFromClipboard);
 
        e.Cancel = true;
    }
}

Bear in mind that the ClipboardEx class is simply an extension of the native Clipboard class for the purposes of RadRichTextBox. In fact, it internally calls Clipboard.GetData(format) when trying to access plain text in the clipboard, so if the  ContainsText() method returns True for you, I don't see a reason the paste to fail.

If you are able to replicate this consistently, could you please try calling the GetData() method in the scenario in which the paste is failing and send over the string so we can look into this?

Thanks for your cooperation in advance.

Regards,
Petya
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Thilo
Top achievements
Rank 1
Iron
answered on 15 Jul 2016, 09:49 AM

Hello Petya,

thank you for your help. I solved the Problem, it was on an other Point !

We preload in our application the RichTextBox MEF Type Catalog like described in http://docs.telerik.com/devtools/wpf/controls/radrichtextbox/mef#explicitly-set-the-necessary-types

in this we are missing to load the TxtFormatProvider.

again, thank you for your help!

Regards,

Thilo

0
Thilo
Top achievements
Rank 1
Iron
answered on 15 Jul 2016, 09:58 AM

About your first question:

The inital Problem was to Paste Plain Text from Clipboard (e.g. from Notepad or Inputfields from other older Applications) in the RadRichTextBox, Text from MS Word did working.

0
Boby
Telerik team
answered on 18 Jul 2016, 07:01 AM
Hello Thilo,

I am glad that you fixed the problem. Let us know if you need additional assistance.

Regards,
Boby
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Flemming
Top achievements
Rank 1
Veteran
answered on 29 Apr 2020, 04:21 PM
[quote]Thilo said:

Hello Petya,

thank you for your help. I solved the Problem, it was on an other Point !

We preload in our application the RichTextBox MEF Type Catalog like described in http://docs.telerik.com/devtools/wpf/controls/radrichtextbox/mef#explicitly-set-the-necessary-types

in this we are missing to load the TxtFormatProvider.

again, thank you for your help!

Regards,

Thilo

[/quote]

 

Thank you! We had the same problem. It used to work, but then we optimized the richtextbox my manually loading the necessary  formatproviders. We missed TxtFormatprovider as well :)

0
Martin
Telerik team
answered on 30 Apr 2020, 04:42 PM

Hello Flemming,

I am happy you found your solution in this forum post. Let me know if there is anything else I can assist you with.

Regards,
Martin
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
RichTextBox
Asked by
Thilo
Top achievements
Rank 1
Iron
Answers by
Petya
Telerik team
Thilo
Top achievements
Rank 1
Iron
Boby
Telerik team
Flemming
Top achievements
Rank 1
Veteran
Martin
Telerik team
Share this question
or