wpf-devexpress-dot-xpf-dot-richedit-dot-richeditcontrol-9dee7adc.md
Fires after each data record is merged with the document in the mail merge process.
Namespace : DevExpress.Xpf.RichEdit
Assembly : DevExpress.Xpf.RichEdit.v25.2.dll
NuGet Package : DevExpress.Wpf.RichEdit
public event MailMergeRecordFinishedEventHandler MailMergeRecordFinished
Public Event MailMergeRecordFinished As MailMergeRecordFinishedEventHandler
The MailMergeRecordFinished event's data class is MailMergeRecordFinishedEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Cancel | Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs. |
| Document | Gets a merged document. |
| MailMergeRegionInfo | Obtains information on the currently merged region. |
| RecordDocument | Gets a template document after a record is merged. |
| RecordIndex | Gets an index of a record currently merged. |
The MailMergeRecordFinished event can be used to post-process the merged section of a document that corresponds to a particular record.
The code sample below shows how to handle the MailMergeRecordStarted and MailMergeRecordFinished events to insert additional content to the document:
View Example: DXRichEdit for WPF: How to use document variable (DOCVARIABLE) fields
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
//...
private static void RichEditControl_MailMergeRecordStarted(object sender, MailMergeRecordStartedEventArgs e)
{
DocumentPosition position = e.RecordDocument.Range.Start;
DocumentRange _range =
e.RecordDocument.InsertText(position, String.Format("Created on {0:G}\n\n", DateTime.Now));
CharacterProperties cp = e.RecordDocument.BeginUpdateCharacters(_range);
cp.FontSize = 8;
cp.ForeColor = Color.Red;
cp.Hidden = true;
e.RecordDocument.EndUpdateCharacters(cp);
}
private static void RichEditControl_MailMergeRecordFinished(object sender, MailMergeRecordFinishedEventArgs e)
{
e.RecordDocument.AppendDocumentContent("Docs\\bungalow.docx", DocumentFormat.Docx);
}
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
'...
Private Shared Sub RichEditControl_MailMergeRecordStarted(ByVal sender As Object, ByVal e As MailMergeRecordStartedEventArgs)
Dim position As DocumentPosition = e.RecordDocument.Range.Start
Dim _range As DocumentRange = e.RecordDocument.InsertText(position, String.Format("Created on {0:G}" & vbLf & vbLf, DateTime.Now))
Dim cp As CharacterProperties = e.RecordDocument.BeginUpdateCharacters(_range)
cp.FontSize = 8
cp.ForeColor = Color.Red
cp.Hidden = True
e.RecordDocument.EndUpdateCharacters(cp)
End Sub
Private Shared Sub RichEditControl_MailMergeRecordFinished(ByVal sender As Object, ByVal e As MailMergeRecordFinishedEventArgs)
e.RecordDocument.AppendDocumentContent("Docs\bungalow.docx", DocumentFormat.Docx)
End Sub
The following code snippets (auto-collected from DevExpress Examples) contain references to the MailMergeRecordFinished event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
dxrichedit-for-wpf-how-to-implement-progress-indicator/CS/MainWindow.xaml#L19
<dx:DXTabItem Header="Template">
<dxre:RichEditControl Name="richEditControl1" Loaded="richEditControl1_Loaded" MailMergeStarted="richEditControl1_MailMergeStarted" MailMergeFinished="richEditControl1_MailMergeFinished" MailMergeRecordStarted="richEditControl1_MailMergeRecordStarted" MailMergeRecordFinished="richEditControl1_MailMergeRecordFinished" />
</dx:DXTabItem>
wpf-richedit-use-docvariable-fields/CS/MainWindow.xaml#L23
<dx:DXTabItem Header="Template">
<dxre:RichEditControl Name="richEditControl1" Loaded="richEditControl1_Loaded" MailMergeStarted="richEditControl1_MailMergeStarted" MailMergeFinished="richEditControl1_MailMergeFinished" MailMergeRecordStarted="richEditControl1_MailMergeRecordStarted" MailMergeRecordFinished="richEditControl1_MailMergeRecordFinished" />
</dx:DXTabItem>
See Also