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
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
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;
}
}
}
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
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
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
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);
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