CodeBasedField CopyPropertiesFrom

9 posts, 0 answers
  1. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 21 Aug 2015 Link to this post

    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


  2. Tanya
    Admin
    Tanya avatar
    402 posts

    Posted 26 Aug 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 09 Sep 2015 in reply to Tanya Link to this post

    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;

                        }

                   }

               } 

  5. Tanya
    Admin
    Tanya avatar
    402 posts

    Posted 14 Sep 2015 Link to this post

    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 result  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
  6. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 17 Sep 2015 in reply to Tanya Link to this post

    It helps Thanks for that. 
  7. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 21 Sep 2015 Link to this post

    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

     

  8. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 24 Sep 2015 Link to this post

    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
  9. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 25 Sep 2015 in reply to Mihail Link to this post

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

     

  10. Tanya
    Admin
    Tanya avatar
    402 posts

    Posted 30 Sep 2015 Link to this post

    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 to 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
Back to Top
UI for WPF is Visual Studio 2017 Ready