Hi,
How can I populate my RichTextBox like the Preview shown in the attachment (codeblock.jpg)?
I tried something like this:
previewTextBox.InsertCodeBlock(codeTextBox.Text, settings);
but the result is not the same (mypreview.jpg)
thank you
3 Answers, 1 is accepted
0
Hello Stefania,
The InsertCodeBlock method used is a correct way to add a code block in RadRichTextBox.
If the visualized code is not formatted in the desired way, could you elaborate on how do you wish that it is displayed? Also, what CodeFormattingSettings are you using when calling the InsertCodeBlock method?
If the CodeFormattingSettings are setup to use the appropriate language, line numbering, alternation, etc. and the result styling of the code block is not the desired one, you could implement a custom tagger that matches your specific needs. You can find more information on how to achieve this in our documentation: https://docs.telerik.com/devtools/wpf/controls/radrichtextbox/features/code-block#code-formatter. Also, you can take a look at our developer-focused example demonstrating how to add custom code formatting language: https://github.com/telerik/xaml-sdk/tree/master/RichTextBox/CustomCodeFormattingLanguage
Hope this helps.
Regards,
Polya
Progress Telerik
The InsertCodeBlock method used is a correct way to add a code block in RadRichTextBox.
If the visualized code is not formatted in the desired way, could you elaborate on how do you wish that it is displayed? Also, what CodeFormattingSettings are you using when calling the InsertCodeBlock method?
If the CodeFormattingSettings are setup to use the appropriate language, line numbering, alternation, etc. and the result styling of the code block is not the desired one, you could implement a custom tagger that matches your specific needs. You can find more information on how to achieve this in our documentation: https://docs.telerik.com/devtools/wpf/controls/radrichtextbox/features/code-block#code-formatter. Also, you can take a look at our developer-focused example demonstrating how to add custom code formatting language: https://github.com/telerik/xaml-sdk/tree/master/RichTextBox/CustomCodeFormattingLanguage
Hope this helps.
Regards,
Polya
Progress Telerik
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

Mattia
Top achievements
Rank 2
answered on 26 Oct 2017, 12:38 PM
Hi, thanks for your reply.
I would like to remove the black border and expand it 100% height and width
0
Hi Stefania,
The code block annotation is internally placed inside a table, which has the black table border. So in order to remove this border, we should get the parent table of our code block and set its Borders to empty borders:
Code blocks stretch by default to 100% of the width of the section they are placed in. If you are working in Paged layout mode and you wish to change the of the sections you could use the ChangeSectionActualPageMargin method:
Regards,
Polya
Progress Telerik
The code block annotation is internally placed inside a table, which has the black table border. So in order to remove this border, we should get the parent table of our code block and set its Borders to empty borders:
// find the annotation start of the first code block.
CodeAnnotationRangeStart codeRangeStart =
this
.radRichTextBox.Document.EnumerateChildrenOfType<CodeAnnotationRangeStart>().First();
Table table = codeRangeStart.GetParentOfType<Table>();
table.Borders =
new
TableBorders();
Code blocks stretch by default to 100% of the width of the section they are placed in. If you are working in Paged layout mode and you wish to change the of the sections you could use the ChangeSectionActualPageMargin method:
this
.radRichTextBox.ChangeSectionActualPageMargin(
new
Telerik.Windows.Documents.Layout.Padding(0));
Regards,
Polya
Progress Telerik
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.