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

CodeBasedField CopyPropertiesFrom

8 Answers 99 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Anand
Top achievements
Rank 1
Anand asked on 21 Aug 2015, 04:15 PM
Hi All,

We have a custom field NoteNumberingField inherited from CodeBasedField, overridden CopyPropertiesFrom , CopyPropertiesFromCodeExpression and
BuildCodeOverride.

NoteNumberingField shows a number in the span and it is rendered below in the xaml. 

<t:FieldRangeStart AnnotationID="2">
<t:NoteNumberingField DateTimeFormatting="" DisplayMode="Result" GeneralFormatting="" NumericFormatting="" Text="1" xmlns:t="clr-namespace:KPMG.TMT.Trinity.Documents.TelerikWpf.Fields;assembly=KPMG.TMT.Trinity.Documents.TelerikWpf" />
</t:FieldRangeStart>
<t:Span FontFamily="Comic Sans MS" FontSize="34.67" Text="1" />
<t:FieldRangeEnd AnnotationID="2" />

When I change the font size of the text from the telerik font size dropdown, I see the overridden method CopyPropertiesFrom get fired and this copies the properties.

But when I change the font size of the same span by code, I dont see the CopyPropertiesFrom being fired as a result I lose all the properties being modified on the span.

So when I say UpdateAllFields on Richtextbox it bring back the default style of the text rather than the previous style what I changed.

In essence when I call RadDocumentEditor.UpdateAllFields, span (inside the field) properties are retained if I have changed using telerik font size drop down, 
but I lose all properties if span properties are changed by code.

Could some one help me in this issue please ? 

Thanks in Advance


8 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 26 Aug 2015, 01:11 PM
Hi Anand,

I tested the described scenario with our DateField which inherits CodeBasedField, but couldn't reproduce the issue you are observing. Could you share how do you set the font size in the code and which is the version of the controls you are using? 

Regards,
Tanya
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
0
Anand
Top achievements
Rank 1
answered on 09 Sep 2015, 03:23 PM

Hi Tanya, 

Sorry for the delayed reply. This is how we set the font size and we use Q2 2015 dlls.

 foreach (var myCell in myRow.Children.OfType<TableCell>())

            {
                myCell.Padding = new Telerik.Windows.Documents.Layout.Padding(-10);

                foreach (var somePara in myCell.Children.OfType<Paragraph>())
                {
                    foreach (var someSpan in somePara.Children.OfType<Span>())
                    {
                        someSpan.FontSize = 2;

                    }

               }

           } 

0
Tanya
Telerik team
answered on 14 Sep 2015, 10:31 AM
Hello Anand,

When showing the document in RadRichTextBox we don't recommend to make direct changes over the elements. For this purpose, you could use the RadDocumentEditor class, which is intended for similar scenarios and triggers important updates after the modifications. 

It is not guaranteed that changing the font size of a Span, part of the field, will call the CopyPropertiesFrom() method. Setting the FontSize of the span will change the size of the font of the   fragment of the field and in order to keep the settings, they should be applied to the code field. This is automatically done by the command used from the UI and by the methods of RadDocumentEditor. You could check how I modified the code-snippet. It selects the first row of a Table and changes its FontSize:
TableRow row = this.radRichTextBox.Document.EnumerateChildrenOfType<TableRow>().First();
DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document);
DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document);
start.MoveToStartOfDocumentElement(row);
end.MoveToEndOfDocumentElement(row);
 
this.radRichTextBox.Document.Selection.SetSelectionStart(start);
this.radRichTextBox.Document.Selection.AddSelectionEnd(end);
 
RadDocumentEditor editor = new RadDocumentEditor(this.radRichTextBox.Document);
editor.ChangeFontSize(2);

Hope this helps.

Regards,
Tanya
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
0
Anand
Top achievements
Rank 1
answered on 17 Sep 2015, 12:24 PM
It helps Thanks for that. 
0
Anand
Top achievements
Rank 1
answered on 21 Sep 2015, 04:33 PM

Does calling ChangeFontSize(fontsize) on the editor brings down the performance ? 

I see my application have gone down in performance on doing this, could you please elaborate ? 

 Thanks in Advance

 

0
Mihail
Telerik team
answered on 24 Sep 2015, 08:49 AM
Hello Anand,

We are unaware of any performance related problems when it comes to changing the font size using the RadDocumentEditor.
Could you give us more information on what is your test scenario? Like how many spans in how many paragraphs and in how many table cells you are using.

Also how did you measure the performance hit? In case, you don't use an external tool I can recommend you our product JustTrace.

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
0
Anand
Top achievements
Rank 1
answered on 25 Sep 2015, 12:58 PM

Hi Mihail,

Its quite a big file that I am going thru. Say we have at-least 100 tables and 50% of the tables are big ones. 

On an average tables have 30 cells, big tables have 100 cells. I am selecting the complete table as below code, before calling the textbox.ChangeFontSize(2). 

With this table selection code it takes 2.30 minutes to complete the process, but when I remove table selection code it takes around 40 seconds only.I ​have suspended document change and content change event as well before doing this. I am pretty sure selecting tables is costing me, and font doesn't change if I don't select the table or cells. Is there any better way to get this work with better performance please ? And I am using latest telerik. 

 Table selection code:

 var firstRow = table.Rows.First(row => row.IsFirst);

 var firstCell = firstRow.Cells.First(cell => cell.IsFirst);
 var lastRow = table.Rows.First(row => row.IsLast);
 var lastCell = lastRow.Cells.First(cell => cell.IsLast);
_associatedRichTextBox.Document.CaretPosition.MoveToStartOfDocumentElement(firstCell);
 var startPosition = new DocumentPosition(_associatedRichTextBox.Document.CaretPosition);
_associatedRichTextBox.Document.CaretPosition.MoveToEndOfDocumentElement(lastCell);
var endPosition = new DocumentPosition(_associatedRichTextBox.Document.CaretPosition);
_associatedRichTextBox.Document.Selection.SetSelectionStart(startPosition);
  _associatedRichTextBox.Document.Selection.AddSelectionEnd(endPosition); ​

 

0
Tanya
Telerik team
answered on 30 Sep 2015, 12:52 PM
Hello Anand,

Indeed, the selection of different parts of the document is a slow operation when many selection ranges are created in a big document. We agree that the performance in this scenario should be improved and there is already a task in our backlog for this. 

However, I am afraid that I am not able to suggest you a suitable approach work around this issue.

Regards,
Tanya
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
Anand
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Anand
Top achievements
Rank 1
Mihail
Telerik team
Share this question
or