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

Mail Merge with CustomMergeField

3 Answers 100 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
band
Top achievements
Rank 1
band asked on 12 Jan 2017, 10:14 PM

Hi, I am successfully able to display the custom merge field(inserts a table into the document) into my RadDocument. The problem I come across is that when I try to save or mail merge I am presented with an error

at Telerik.Windows.Documents.Layout.LayoutBox.InvalidateMeasure()
at Telerik.Windows.Documents.Layout.LayoutBox.InvalidateMeasureUpToTheRoot()
at Telerik.Windows.Documents.Layout.LayoutBox.OnAssociateDocumentElementChangedCore()
at Telerik.Windows.Documents.Layout.LayoutBox.set_AssociatedDocumentElement(DocumentElement value)

Am I doing anything wrong while creating a MergeField? Is the xamlserializer causing the error?

public class CustomMergeField : MergeField
{
    private const string CustomFieldName = "CustomField";
 
    static CustomMergeField()
    {
        CodeBasedFieldFactory.RegisterFieldType(CustomMergeField.CustomFieldName, () => { return new CustomMergeField(); });
    }
 
    public override string FieldTypeName
    {
        get
        {
            return CustomMergeField.CustomFieldName;
        }
    }
 
    public override Field CreateInstance()
    {
        return new CustomMergeField();
    }
     
    protected override DocumentFragment GetResultFragment()
    {
        UniversalDTO universalDTO = this.Document.MailMergeDataSource.CurrentItem as UniversalDTO;
        if (universalDTO == null)
        {
            return null;
        }
 
        if (this.PropertyPath == "Collaterals")
        {
            Table table = new Table();
 
            foreach (var coillateral in universalDTO.Collaterals)
            {
                Span span = new Span(coillateral.Type.Value);
                span.FontSize = 11.5;
                Paragraph paragraph = new Paragraph();
                paragraph.Inlines.Add(span);
 
                Span span2 = new Span(coillateral.Description);
                span2.FontSize = 11.5;
                Paragraph paragraph2 = new Paragraph();
                paragraph2.Inlines.Add(span2);
 
                TableCell cell = new TableCell();
                cell.Blocks.Add(paragraph);
                cell.Borders = new TableCellBorders(new Border(1, BorderStyle.Single, Colors.Transparent));
 
                TableCell cell2 = new TableCell();
                cell2.Blocks.Add(paragraph2);
                cell2.Borders = new TableCellBorders(new Border(1, BorderStyle.Single, Colors.Transparent));
 
                TableRow row = new TableRow();
                row.Cells.Add(cell);
                row.Cells.Add(cell2);
                table.AddRow(row);
            }
 
            Section section = new Section();
            section.Blocks.Add(table);
 
            RadDocument document = new RadDocument();
            document.Sections.Add(section);
 
            document.MeasureAndArrangeInDefaultSize();
            return new DocumentFragment(document);
        }
 
        return null;
    }
}

3 Answers, 1 is accepted

Sort by
0
band
Top achievements
Rank 1
answered on 13 Jan 2017, 10:38 PM

I've built a sample project of the  


* Edited by administrator *

0
band
Top achievements
Rank 1
answered on 16 Jan 2017, 04:24 PM
After looking deep into this, it looks like it will only fail when you try to mail merge when it's in preview result mode.
0
Accepted
Tanya
Telerik team
answered on 17 Jan 2017, 03:41 PM
Hello,

The issue you are observing is already fixed in the newer versions of the control. The only thing I can suggest you is to upgrade the controls you are using to a newer version.

Your post has been edited as the project you shared contains binaries from the suite. We have to avoid publishing the dev assemblies in publicly accessible sites as they are distributed with a license per developer seat.

Regards,
Tanya
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
band
Top achievements
Rank 1
Answers by
band
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or