Change font size - using Q2 Telerik

2 posts, 0 answers
  1. Todd
    Todd avatar
    5 posts
    Member since:
    Aug 2010

    Posted 25 Jan 2011 Link to this post

    I use the Telerik radRichTextBox in a Telerik gridview.  I need to make the font smaller in the richtextbox.  I am using Telerik Silverlight 2010 Q2.  My company does not want to upgrade to a newer version of the silverlight Telerik controls.  How can I change the font size in my richtextbox?  Here is the richtextbox code from my XAML, and from my code-behind:
    <telerik:GridViewDataColumn Header="Notes" MinWidth="120" MaxWidth="200" IsReadOnly="True" DataMemberBinding="{Binding task.notes}">
                       <telerik:GridViewDataColumn.CellTemplate>
                           <DataTemplate>
                               <telerik:RadRichTextBox x:Name="readOnlyRichTextBox" Height="50" IsReadOnly="True">
                                  <telerik:RadRichTextBox.Resources>
                                       <telerikDocumentXaml:XamlDataProvider x:Key="XamlDataProvider" SetupDocument="XamlDataProvider_SetupDocument"
                                                             RichTextBox="{Binding ElementName=readOnlyRichTextBox}"
                                                             Xaml="{Binding task.notes, Mode=TwoWay}"  />
                                   </telerik:RadRichTextBox.Resources>
                                    
     
                               </telerik:RadRichTextBox>
                           </DataTemplate>
                       </telerik:GridViewDataColumn.CellTemplate>
                   </telerik:GridViewDataColumn>


    private void XamlDataProvider_SetupDocument(object sender, Telerik.Windows.Documents.FormatProviders.SetupDocumentEventArgs e)
            {
               e.Document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(0, 0, 0, 0);
            }
  2. Mike
    Admin
    Mike avatar
    640 posts

    Posted 27 Jan 2011 Link to this post

    Hi Todd,

    2010 Q2 was the first official release of RadRichTextBox for Silverlight and the APIs is not as convenient as it is with later versions. However we found a workaround to change the default font of documents in your scenario. You can try modifying the SetupDocument event handler the following way:

    private void XamlDataProvider_SetupDocument(object sender, Telerik.Windows.Documents.FormatProviders.SetupDocumentEventArgs e)
    {
        e.Document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(0, 0, 0, 0);
     
        //Set the default font size for an empty document
        e.Document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
        e.Document.Arrange(new RectangleF(PointF.Empty, e.Document.DesiredSize));
        ((Span)e.Document.CaretPosition.GetCurrentInlineBox().AssociatedDocumentElement).FontSize = 8;
     
        //Set the font size of an existing document
        e.Document.Selection.SelectAll();
        e.Document.UpdateSelectedSpansStyle(
            (span) =>
            {
                span.FontSize = 8;
                return span;
            }
        );
    }
    Please try it and let us know if it works for you. We strongly recommend though upgrading to a more recent newer version of Telerik Silverlight tools to avoid other problems already resolved.

    Best wishes,
    Mike
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top