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
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
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!
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
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
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.
I am glad that you fixed the problem. Let us know if you need additional assistance.
Regards,
Boby
Telerik by Progress
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 :)
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
Our thoughts here at Progress are with those affected by the outbreak.