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

Trouble with the CreateDeepCopy() method: loosing the default FontSize

2 Answers 72 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Art
Top achievements
Rank 1
Art asked on 21 Oct 2015, 08:26 AM

I'm trying to merge several documents to one.

All elements in the Edit mode presented by separate RadRichTextBox. Print Mode unites their XamlDocuments.

Trouble:

RadRichTextBox have it's DefaultFontSize = 13pt (ValueSource of Span = RadValueSource.Parent).

I'v change the font size of the neighboring Span from 13 to 14 and then 13 (ValueSource = RadValueSource.Local).

When a large document is constructed by deepCopy of all blocks, span with unchanged FontSize becomes 12pt. But the modified Span remains 13pt.

  

​Where it takes this «terrible» 12pt? There is no document after DeepCopy, am I right?

How to apply initial FontSize to "Parent" values of copied elements? Block can be a table with many cells. Each with spans of 12pt parent... Deep cycling to replace?

2 Answers, 1 is accepted

Sort by
0
Art
Top achievements
Rank 1
answered on 21 Oct 2015, 09:06 AM

My own solution:

 

foreach (var copyBlock in document.Sections.SelectMany(section => section.Blocks))
{
    var block = copyBlock.CreateDeepCopy() as Block;
 
    CheckInlines(block);
    yield return block;
}

 Implementation:

private void CheckInlines(Block block)
{
    foreach (var item in block.Children)
    {
        var b = item as Block;
 
        if (b != null)
        {
            CheckInlines(b);
            continue;                   
        }
 
        var span = item as Span;
 
        if (span != null && !span.GetStyleProperty(Span.FontSizeProperty).HasLocalValue())
            span.FontSize = Unit.PointToDip(Settings.ElementSettings.FontSize);
    }
}

 

Is there another way? Thanks.

 

0
Mihail
Telerik team
answered on 23 Oct 2015, 08:28 AM
Hello Artur,

The behavior you described is expected. When you create a deep copy of span the font size will be default as it doesn't have from where to inherit any other value. Once you add it to another document all style properties will be evaluated again, including the font-size. This means that if there is no other value regarding the font-size except the value in the document itself the font-size will have the value applied to RadDocument.Style.Style.SpanProperties.FontSize property.

I hope this information is helpful for you.

Regards,
Mihail
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Art
Top achievements
Rank 1
Answers by
Art
Top achievements
Rank 1
Mihail
Telerik team
Share this question
or