Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > RichTextBox > Setting the font-size and font-family of an whole existing RadDocument

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

Feed from this thread
  • Lukas avatar

    Posted on May 15, 2012 (permalink)

    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

    Reply

  • Answer Vasil Vasil admin's avatar

    Posted on May 18, 2012 (permalink)

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

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > RichTextBox > Setting the font-size and font-family of an whole existing RadDocument