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

UpdateAllFields and custom fields

3 Answers 99 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Charles
Top achievements
Rank 1
Charles asked on 14 Jan 2015, 03:04 PM
Hi

I've noticed that in 2014.3.1021 there have been some performance enhancements to UpdateAllFields.  I'm not entirely sure what they are, but if I was to guess I'd say the document is no longer being layed out, mesaured and arranged after each field update.

This has, sadly, broken one of my custom fields.

I have a sort-of-cross reference field - it returns the page number of a custom AnnotationRangeStart.  It does this in basically the same way as PageField.

Following the update to this version, the page number is always returned as '1' during UpdateAllFields.  This seems to be because the layout only reports a single SectionLayoutBox in the DocumentLayoutBox.

I see from the PageField source two internal virtual methods that you use to workaround this issue: SaveState and RestoreState.  As these are internal and not protected internal, I can't do the same.

My current workaround is to run Document.UpdateLayout() while this field is updating, which isn't ideal.  Do you have any better ideas, or would you consider changing the accessibility of these internal state management methods?







3 Answers, 1 is accepted

Sort by
0
burk
Top achievements
Rank 1
answered on 15 Jan 2015, 08:35 AM
If i understand, you must catch merge fields first with:
private List<MergeField> mergeFields;
private void GetMergeFieldStarts()
        {
            #region MergeField'ların Bulunması
 
            mergeFields.Clear();
            foreach (FieldRangeStart fieldStart in radRichTextBox.Document.EnumerateChildrenOfType<FieldRangeStart>())
            {
                if (fieldStart.Field is MergeField)
                {
                    mergeFields.Add(fieldStart);
                }
            }
            #endregion
        }
And you can get your merge fields propertyPaths with foreach.
If you catch true Field you can get this control with
foreach (var item in mergeFields)
            {
                if (((MergeField)item.Field).PropertyPath == "YourPropertyPath")
                {
                    FieldRangeStart field = (FieldRangeStart)item;
                    var fieldsControl= FindControlFieldMethod(field.Parent);
 
                    YourControlType control= (YourControlType)fieldsControl;
                    
                    
 
 
                }
 
 
            }
And If find true PropertyPath you can find your control with:
private DocumentElement FindControlFieldMethod(DocumentElement documentElement)
        {
            if (documentElement is YourControlType)
            {
                return documentElement;
            }
            else
            {
                return FindControlFieldMethod(documentElement.Parent);
            }
 
        }
0
Charles
Top achievements
Rank 1
answered on 15 Jan 2015, 03:09 PM
Thanks for the answer, but I'm not sure how this is relevant to my question.  I don't have any MergeFields, and I don't have any controls to find.

My issue is as I described: during UpdateAllFields, the Layout is not valid and I can't get correct PageNumbers.
0
Petya
Telerik team
answered on 15 Jan 2015, 05:19 PM
Hi Charles,

There is currently an issue with the UpdateAllFields() method which does not cause the document layout to be wrong, but updates the fields with wrong values. This is logged in our public portal here and as mentioned in the item, the workaround is to update each field separately. Could you try this out and let us know how it works for you?

Regards,
Petya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
RichTextBox
Asked by
Charles
Top achievements
Rank 1
Answers by
burk
Top achievements
Rank 1
Charles
Top achievements
Rank 1
Petya
Telerik team
Share this question
or