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

Change font size - using Q2 Telerik

1 Answer 186 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Todd
Top achievements
Rank 1
Todd asked on 25 Jan 2011, 06:06 PM
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);
        }

1 Answer, 1 is accepted

Sort by
0
Mike
Telerik team
answered on 27 Jan 2011, 03:15 PM
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>>
Tags
RichTextBox
Asked by
Todd
Top achievements
Rank 1
Answers by
Mike
Telerik team
Share this question
or