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

Setting font in RadRichTextBox with RTF

4 Answers 265 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Sander
Top achievements
Rank 1
Sander asked on 09 Aug 2011, 11:15 AM
Hi,

I have a RadRichTextBox and I'm trying to set the default font, but I can't get it to change.
I tried setting DocumentInheritsDefaultStyleSettings and I tried setting it in RadRichTextBox.Document tag, but it doesnt work.
Please explain me how to set the font.

This is my xaml:

                                    <telerikDoc:RadRichTextBox Grid.Row="5" Grid.Column="1" MinWidth="300" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                        IsContextMenuEnabled="True" IsReadOnly="False" IsSelectionMiniToolBarEnabled="False" LayoutMode="FlowNoWrap" AcceptsReturn="True"
                                        IsSpellCheckingEnabled="False" x:Name="radRichTextBox" DocumentInheritsDefaultStyleSettings="False" FontSize="10" >
                                        <telerikDoc:RadRichTextBox.Document>
                                            <telerik:RadDocument>
                                                <telerik:Section>
                                                    <telerik:Paragraph FontSize="24"/>
                                                </telerik:Section>
                                            </telerik:RadDocument>
                                        </telerikDoc:RadRichTextBox.Document>
                                        <telerikDoc:RadRichTextBox.Resources>
                                            <rtf:RtfDataProvider x:Key="provider" RichTextBox="{Binding ElementName=radRichTextBox}"
                                                Rtf="{Binding Path=Content, Mode=TwoWay}" SetupDocument="RtfDataProvider_SetupDocument">
                                            </rtf:RtfDataProvider>
                                        </telerikDoc:RadRichTextBox.Resources>
                                    </telerikDoc:RadRichTextBox>

4 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 09 Aug 2011, 04:59 PM
Hello Sander,

Setting the default style settings as described here only works for documents that do not set their style settings, e.g. if you create a new document and set it to RadRichTextBox's Document property or import a plain-text document. RTF being a rich text format, it will probably contain settings for font-family and font-size. If you remove those, the default ones must be inherited.
Furthermore, you need to set the DocumentInheritsDefaultStyleSettings property of RadRichTextBox to True and not to False.
The declaration of the Document will not be of any use, as the data providers create new documents for every change in the string property they are bound to.

All the best,
Iva
the Telerik team

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

0
Sander
Top achievements
Rank 1
answered on 10 Aug 2011, 09:58 AM
I'm sorry, but I still don't understand how this works. What I'm trying to do is the following: I use the RadRichTextBox to create a new document, which should be RTF. So the content it is bound to is empty to start with (string.empty to be precise). Now, where can I specify the fontsize and fontfamily, so that when the user starts typing it has the correct font and size?
0
Sander
Top achievements
Rank 1
answered on 10 Aug 2011, 01:08 PM
I see now that the fontfamily does change when I set it in xaml, but not the fontsize...
0
Iva Toteva
Telerik team
answered on 15 Aug 2011, 02:43 PM
Hello Sander,

On further investigation, it seems that the problem is that the DataProvider is included in the resources of RadRichTextBox. As described in our online documentation, the data providers have to be declared in the visual tree, so that their context is properly updated.
Please find attached a demo, which shows how a RadRichTextBox uses the FontSize and FontFamily specified on the RadRichTextBox.
The default font size specified in XAML is 40 pt, which is equal to 30 DIP - the unit that the SelectionMiniToolBar and RadRichTextBoxRibbonUI use.

Kind regards,
Iva
the Telerik team

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

Tags
RichTextBox
Asked by
Sander
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Sander
Top achievements
Rank 1
Share this question
or