This is a migrated thread and some comments may be shown as answers.

how to change the default FontFamily for the RadRichTextBox?

3 Answers 493 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
ji
Top achievements
Rank 1
ji asked on 19 Oct 2010, 09:50 AM
<telerik:RadRichTextBox.Document >
                    <telerik:RadDocument>
                        <telerik:Section>
                            <telerik:Paragraph FontSize="12" />
                        </telerik:Section>
                    </telerik:RadDocument>
                </telerik:RadRichTextBox.Document>

-----------
this code can not change FontFamily 

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 20 Oct 2010, 07:23 AM
Hi ji,

You can set the FontSize at Paragraph level, but FontFamily, FontWeight, FontStyle and a few other properties are available only at Span level. This is how they can be set:
<telerik:RadRichTextBox >
    <telerik:RadRichTextBox.Document>
        <telerik:RadDocument>
            <telerik:Section>
                <telerik:Paragraph FontSize="14">
                    <telerik:Span FontFamily="Arial Black" FontStyle="Italic" Text="example" />
                </telerik:Paragraph>
            </telerik:Section>
        </telerik:RadDocument>
    </telerik:RadRichTextBox.Document>
</telerik:RadRichTextBox>

If you have any other questions, feel free to get back to us.

All the best,
Iva
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
tj
Top achievements
Rank 1
answered on 28 Oct 2010, 03:18 AM
Thanks for your reply!

Is there a way to do it code-behind? I tried to set it in the document, but I cannot find the property.
0
Iva Toteva
Telerik team
answered on 29 Oct 2010, 12:24 PM
Hello Tj,

We have planned to introduce properties to change the default font settings in the next official release (in a couple of weeks).
Until then, you can set them in code-behind like this:
For Q2 2010 SP2:
this.Dispatcher.BeginInvoke(() =>
            {
               Span firstSpan = this.radRichTextBox.Document.Sections.First.Paragraphs.First.Inlines.First as Span;
               firstSpan.FontStyle = FontStyles.Normal;
               firstSpan.FontFamily = new System.Windows.Media.FontFamily("Comic sans MS");
               firstSpan.FontSize = 20;
            });

For Q3 2010 Beta:
this.Dispatcher.BeginInvoke(() =>
           {
               Section firstSection = this.radRichTextBox.Document.Sections.First;
               Span firstSpan = (firstSection.Blocks.First as Paragraph).Inlines.First as Span;
               firstSpan.FontStyle = FontStyles.Normal;
               firstSpan.FontFamily = new FontFamily("Comic sans MS");
               firstSpan.FontSize = 20;
           });

This piece of code can be added in your handler of the Loaded event, for example.
If you have any other questions, feel free to contact us again.

Greetings,
Iva
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
ji
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
tj
Top achievements
Rank 1
Share this question
or