0

我需要快速支持来填充 radrichtextbox 上的邮件合并数据。在第一步中,我只是在邮件合并中填充数据列表,如“FirstName”、“LastName”,然后我想获取与这些标签关联的数据,例如 Firstname=Peter ....请查看以下行代码。我的问题是如何在按预览结果时在文档上加载 FirstName、LastName 数据。

负载

this.radRichTextBox.Document.MailMergeDataSource.ItemsSource = new List<Employee>()
            {
                new Employee()
                {
                    FirstName = "Guest1",
                    LastName = "Guest2",  
                },
                new Employee()
                {
                    FirstName = "Ali",
                    LastName = "Doc", 
                }
            };

private void btnPrint_Click(object sender, RoutedEventArgs e)
       {
           //this.radRichTextBox.InsertField(new MergeField() { PropertyPath = "FirstName" });
           MergeField field = new MergeField() { PropertyPath = "FirstName" };
           field.DisplayMode = FieldDisplayMode.Result;
           this.radRichTextBox.Document.ChangeFieldDisplayMode(field.FieldStart, FieldDisplayMode.Result);
    }
4

1 回答 1

0

You can insert a merge field in RadRichTextBox's RadDocument using the InsertField method of RadRichTextBox:

this.radRichTextBox.InsertField(new MergeField() { PropertyPath = "FirstName" }, FieldDisplayMode.Result);

Note that the display mode is set to FieldDisplayMode.Result during the insertion, this will ensure that the field will be evaluated immediately using the data source.

The fields in RadRichTextBox have three display modes: Code, DisplayName and Result. If you have inserted the fields in Code or DisplayName modes, you can change the mode of all fields in the document at later time (after the insert) using the following:

this.radRichTextBox.ChangeAllFieldsDisplayMode(FieldDisplayMode.Result);
于 2015-03-27T22:34:51.603 回答