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

2 posts, 1 answers
  1. Lukas
    Lukas avatar
    20 posts
    Member since:
    Jul 2011

    Posted 15 May 2012 Link to this post

    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
  2. Answer
    Vasil
    Admin
    Vasil avatar
    124 posts

    Posted 18 May 2012 Link to this post

    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 >>

  3. DevCraft banner
Back to Top