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

3 posts, 0 answers
  1. Art
    Art avatar
    23 posts
    Member since:
    Apr 2015

    Posted 21 Oct 2015 Link to this post

    I'm trying to merge several documents to one.

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


    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. Art
    Art avatar
    23 posts
    Member since:
    Apr 2015

    Posted 21 Oct 2015 Link to this post

    My own solution:


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


    private void CheckInlines(Block block)
        foreach (var item in block.Children)
            var b = item as Block;
            if (b != null)
            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.


  3. DevCraft banner
  4. Mihail
    Mihail avatar
    192 posts

    Posted 23 Oct 2015 Link to this post

    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.

    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
Back to Top