Pasting Plain Text from Clipboard

7 posts, 0 answers
  1. Thilo
    Thilo avatar
    26 posts
    Member since:
    Feb 2011

    Posted 10 Jun 2015 Link to this post

    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

  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 12 Jun 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Thilo
    Thilo avatar
    26 posts
    Member since:
    Feb 2011

    Posted 14 Jul in reply to Petya Link to this post

    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!

  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 15 Jul Link to this post

    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.
  6. Thilo
    Thilo avatar
    26 posts
    Member since:
    Feb 2011

    Posted 15 Jul in reply to Petya Link to this post

    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

  7. Thilo
    Thilo avatar
    26 posts
    Member since:
    Feb 2011

    Posted 15 Jul in reply to Thilo Link to this post

    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.

  8. Boby
    Admin
    Boby avatar
    595 posts

    Posted 18 Jul Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready