wpf - RichTextBox places linefeeds into Run element text property -


I want to be able to paste text directly into the RichTextBox control while preserving tabs, line-feeds and new-lines. Unfortunately, when you paste text from the clipboard (Ctrl-V), then the '\ r' character is returned to & lt; Instead of being translated into LineBreak, the text of the moved element is being retained in the property / & gt; Element

So, given the paste of text:

And it is very simple and quickly refined.

Nam libero tempore, cum soluta nobis est Eligendi Optio Cumque nihil impedit status quo minus id quod Maxime Placeat Facere Possimus, Omnis Voluptas Assumenda est, Omnis weeds repellendus.

And ...

  & lt; RichTextBox x: Name = "rtbNoteText" BorderBrush = "Grey" xml: space = "preserve" AcceptsReturn = "True" TextWrapping = "wrap" BorderThickness = "1" HorizontalAlignment = "muscle" Grid.Row = "1" VerticalAlignment = " Muscles "margin =" 30,0,30,30 "fONTSIZE =" 14 "VerticalScrollBarVisibility =" viewable "horizontalScrollBarVisibility =" auto "/> Private void btnSaveNote_Click (object sender, RoutedEventArgs e) {if (! String.IsNullOrEmpty (rtbNoteText.Xaml)) {string content = rtbNoteText.Xaml; }}   

The contents of rtbNoteText.Xaml are:

  & lt; Section xml: space = \ "protect \" trailingprogramfreakpoint = \ "false \" xmlns = \ "http: //schemas.microsoft.com/winfx/2006/xaml/presentation \" & gt; & Lt; Article FONTSIZE = \ "14 \" FontFamily = \ "Portable User Interface \" foreground = \ "# FF000000 \" FontWeight = \ "normal \" FontStyle = \ "normal \" FontStretch = \ "normal \" TextAlignment = \ " Left \ "& gt; . & Lt; Run text = \ "at Harum quidem rerum Facilis est et expedita distinctio \ r \ rNam libero tempore, cum soluta nobis est Eligendi Optio Cumque nihil impedit status quo minus id quod Maxime Placeat Facere Possimus, Omnis Voluptas Assumenda est, Omnis weeds repellendus . \ / / Gt; & lt; / paragraph & gt; & lt; / section>   

rtbNoteText.Replace ("\ r", " Will not move because the line feeds are embedded within the Run element text property.

Is there a standard way to get it instead ?:

  & lt; experience P. & gt; & lt; Paragragh & gt; Run & gt; ... & lt; / Run & gt; & gt; LineBreak / & gt; & lt; LineBrack / & gt; & lt; Run & Gt; ... & lt; / Run & gt; & lt; / para & gt; & lt; / section & gt;    

You can manually create a paragraph object by adding objects to each line of your text and whenever you need a line break, you split into lines using your text method can do.

Below is an example:

  string text = "It is very easy and it has brought sharpness to precision. \ R \ r" + "Only time free But we choose the right option for all and it can be reduced by at least zero. "+" The most likely is that, affects all types of changes. "; // I think how you are updating textbox now, //richtextbox.Selection.Text = text; Paragraph paragraph = new paragraph (); String [] line = text Sample (new four [] {'\ r'}); For (int i = 0; i  height; i ++) {paragraph.Inlines.Add (new run) {text = lines [i]}); If (i & lt; lines.Length - 1) paragraph.inline. Add (new linebreak ()); } RichTextBox.Blocks.Add (paragraph);   

This will give you the Retail Textbox. The following xaml should be returned via XML property:

  & lt; Section xml: space = "protected" hatreding paragraphbreak onpest = "falls" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" & gt; & Lt; Paragraph Fontsij = "11" Fontfamili = "Portable User Interface" foreground = "# FF 2000000" Fontveit = "Normal" font-style = "normal" font-Stacc = "normal" Tekstelinment = "left" & gt; & Lt; Run Less = "This definitely enhances the simplicity and clarity." / & Gt; & Lt; Linereck / & gt; & Lt; Run /> & Lt; Linereck / & gt; & Lt; Run text = "It is free for the time, we can only choose one option and at least four times" /> & lt; Linereck / & gt; & Lt; Run text = "To complete all the places, all the tasks have been effectively changed." / & Gt; & Lt; / Paragraph & gt; & Lt; / Section & gt;   

Hope this helps,

Comments