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

Setting the font-size and font-family of an whole existing RadDocument

1 Answer 429 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Lukas
Top achievements
Rank 1
Lukas asked on 15 May 2012, 12:20 PM
I have a RadRichTextBox. The content is bound via an HtmlDataProvider. I bound a string property to the Html-Property of the provider. This property is in my ViewModel.

Now how can I set all the content of my RadDocument to the same font-size and font-family?

myEditor.FontFamily = new FontFamily("FontName"); // didn't change anything

1 Answer, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 18 May 2012, 12:46 PM
Hi Lukas,
You can set the default font properties of your RadDocument using RadRichTextBox.DocumentInheritsDefaultStyleSettings property, as described in this help article. Keep in mind that RadRichTextBox's default values for font style (FontFamily, FontSize, etc.) are applied to the document elements only if it the don't have such properties locally set - but HtmlFormatProvider creates document elements and sets its formatting properties according to the HTML specification (which default values are Times New Roman, 12). If you experience such issue, you can try to explicitly clear the values of the imported spans in the data providers's SetupDocument event, for example:
private void HtmlDataProvider_SetupDocument(object sender, SetupDocumentEventArgs e)
{
    foreach (Span span in e.Document.EnumerateChildrenOfType<Span>())
    {
        span.ClearValue(Span.FontSizeProperty);
        span.ClearValue(Span.FontFamilyProperty);
        span.ClearValue(Span.FontStyleProperty);
        span.ClearValue(Span.FontWeightProperty);
    }
}
Don't hesitate to contact us if you have any other questions.


Regards,
Vasil
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Lukas
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or