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

How to set new default fontsize but not influencing the text which has been inputed

3 Answers 75 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Chen
Top achievements
Rank 1
Chen asked on 04 Nov 2010, 03:21 AM
Hello,

When I input something and try to set new default fontsize ,some text which have been inputed will be changed too.
    Span span= control.editor.Document.Sections.Last.Paragraphs.Last.Inlines.Last.PreviousSibling as Span;                
    span.FontSize = fontsize;
I know the reason is that all the text in the Paragraphs.Last.Inlines.Last  will be changed. But I don't know how to solve it, because I can't get the DocumentElement which have not been inputed.

And the demo http://demos.telerik.com/silverlight/beta/#RichTextBox/MSWord doesn't have this problem too. But I can find the codes about    telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ChangeFontSizeCommand} (I think this command deal with the problem). Or Is it the problem of the version?

Thanks.
Chen

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 05 Nov 2010, 08:33 AM
Hello Chen,

The code snippet
Span span = control.editor.Document.Sections.Last.Paragraphs.Last.Inlines.Last as Span;
span.FontSize = fontsize;

sets the font size of the last Span in the document. Thus, as expected, the text in that last Span changes too.
You cannot set the font size of the next Span, because it is not created at that point.
The command, on the other hand, creates a new Span, because different font properties require different Spans. That is why it works correctly.

There will be properties for default font style, size, weight, etc. in Q3 2010 official release, which is due in a few weeks' time. Then, each newly-created Span will have its properties set to the default ones.



Kind regards,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chen
Top achievements
Rank 1
answered on 08 Nov 2010, 02:52 AM
Hello Iva,

      How to add the new Span?

          Span span=new Span();
     control.editor.Document.Sections.Last.Paragraphs.Last.Inlines.Add(span);

   There will be a exception throwed up.

Thanks.
Chen
0
Iva Toteva
Telerik team
answered on 11 Nov 2010, 09:07 AM
Hi Chen,

You cannot add Spans that do not have any content. This is how RadRichTextBox works by design. If you insist on using Q2 SP2, you can workaround that by adding a Span that only consists of whitespace, e.g. 

Span span=new Span(" ");
control.editor.Document.Sections.Last.Paragraphs.Last.Inlines.Add(span);
but that is not a neat solution to the problem.

Since our Q3 Release has already become fact, you can try using the default font properties, which set the font of the elements that do not explicitly assign them. This is how you do that:
<telerik:RadRichTextBox Name="radRichTextBox" FontFamily="Comic Sans MS" FontSize="20" DocumentInheritsDefaultStyleSettings="True">
    <telerik:RadRichTextBox.Document>
        <telerik:RadDocument>
            <telerik:Section>
                <telerik:Paragraph>
                    <telerik:Span Text="some text in default font" />
                </telerik:Paragraph>
                <telerik:Paragraph>
                    <telerik:Span FontFamily="Georgia" Text="some text in Georgia" />
                </telerik:Paragraph>
            </telerik:Section>
        </telerik:RadDocument>
    </telerik:RadRichTextBox.Document>
</telerik:RadRichTextBox>

Let us know if you find these suggestions useful.


Regards,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Chen
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Chen
Top achievements
Rank 1
Share this question
or