RichTextBox binding Text changes fontsize

Aug 31, 2012 at 9:34 AM

Hi all,

I'm using your bindable RichTextBox in my project because of its binding capabilities.
I've noticed I have an issue with the fontsize of its content when I bind the TextProperty to a string that is not in Rtf format.

For instance,

var richTextBox = new Xceed.Wpf.Toolkit.RichTextBox()
    FontSize = 10,
    SelectionFontSize = 10, 
    FontStyle = node.FontStyle,
    FontWeight = node.FontWeight,
    FontFamily = node.FontFamily ?? new FontFamily("Arial")

richTextBox.SetBinding(Xceed.Wpf.Toolkit.RichTextBox.TextProperty, binding);

with the binding that points to a string property that can contain Rtf or plaintext.
In the first case the RtfFormatter kicks in and the rendered fontsize is correct.
In the second case (plaintext), what I end up with is a richtextbox containing a Selection.Text that has a FontSize = 16.

Does this happen to somebody else too?

Aug 31, 2012 at 9:51 AM

I guess I might be doing things wrong...

I've noticed that even without the binding, I have the same issue if I set the richTextBox.Text = "this is a plaintext".
While I don't have a changed fontsize if I do richTextBox.Selection.Text = "this is a plaintext";

How should I bind then my strings to the richtextbox?

Aug 31, 2012 at 1:57 PM

The default TextFormatter is a RichTextFormatter wich expect the content of the "Text" property to be a string containing the "rich text data" like the following:


{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs18\f2\cf0 \cf0\ql{\f2 {\lang4105\highlight1\ltrch test}\li0\ri0\sa0\sb0\fi0\ql\par}



Try to initialize the TextFormater to a PlainTextFormatter:

            <xctk:RichTextBox >

Or in code behind:


RichTextBox rtb = new RichTextBox();
rtb.TextFormatter = new PlainTextFormatter();