# Mail Merge Examples

> Mail merge samples for TX Text Control .NET for WPF: simple merges, merge blocks, nested blocks, the TX Words Reporting sample and reusable MailMerge samples.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Examples > Mail Merge Examples
- **1727 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/mail-merge/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/mail-merge/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/mail-merge/llms-full.txt

---

[MailMerge](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver/mailmerge/llms-full.txt) creates documents such as invoices, letters and reports from a template and data. In a WPF application, the template can be the document of the `TextControl` in your window: the WPF samples assign the control to [TextComponent](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver/mailmerge/textcomponent-property/llms-full.txt). The official samples show the basics, and further samples written for Windows Forms or TX Text Control .NET Server show techniques with the same `MailMerge` class.

### WPF Samples

The setup installs these samples, and [TXSamples\_WPF\_CSharp](https://github.com/TextControl/TXSamples_WPF_CSharp) and [TXSamples\_WPF\_VB.NET](https://github.com/TextControl/TXSamples_WPF_VB.NET) contain them for version 32.0, for the .NET Framework 4.8 and .NET 6:

| Example | What it shows | Where |
|---|---|---|
| Simple merge | Merge fields inserted from menu items built from the columns of an XML data set, then filled with [Merge](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver/mailmerge/merge-method/llms-full.txt) | [TXSamples\_WPF\_CSharp](https://github.com/TextControl/TXSamples_WPF_CSharp), folder *Howto\\MailMerge\\MailMerge\_Simple* |
| Merge blocks | A DOCX template with a merge block, a section repeated for each record, filled with the orders of a data set | [TXSamples\_WPF\_CSharp](https://github.com/TextControl/TXSamples_WPF_CSharp), folder *Howto\\MailMerge\\MailMerge\_Blocks* |
| Nested merge blocks | A report with blocks inside blocks, filled from related tables, and a progress bar updated in [BlockRowMerged](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver/mailmerge/blockrowmerged-event/llms-full.txt) | [TXSamples\_WPF\_CSharp](https://github.com/TextControl/TXSamples_WPF_CSharp), folder *Howto\\MailMerge\\MailMerge\_Nested\_Blocks* |
| TX Words Reporting | Templates for an invoice, a packing list and a shipping label, designed with a sample database in the reporting tab of the ribbon and merged with the [DataSourceManager](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-datasources/datasourcemanager/llms-full.txt) that [RibbonReportingTab.DataSourceManager](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonreportingtab/datasourcemanager-property/llms-full.txt) returns | [TXSamples\_WPF\_CSharp](https://github.com/TextControl/TXSamples_WPF_CSharp), folder *TX Words* |

The export dialog of the Reporting sample on GitHub saves DOCX files with `StreamType.SpreadsheetML`, the Excel format; for DOCX, use `StreamType.WordprocessingML`.

### Other Samples

These samples were written for other products. Their `MailMerge` code is the same in WPF; replace a Windows Forms `TextControl` with the WPF `TextControl` or a `ServerTextControl`:

| Example | What it shows | Where |
|---|---|---|
| Dynamic contracts | Sections of a contract template included or left out according to JSON data, as described in [Generating Dynamic NDAs Using TX Text Control MailMerge in C# .NET](https://www.textcontrol.com/blog/2025/04/08/generating-dynamic-ndas-using-tx-text-control-mailmerge-in-csharp-dotnet/). A console application for TX Text Control .NET Server, .NET 8, version 33.0 | [TXTextControl.Server.NDA.Dynamic](https://github.com/TextControl/TXTextControl.Server.NDA.Dynamic) |
| Mustache placeholders | A class that turns `{{placeholders}}` into merge fields and merge blocks, as described in [Mail Merge: Merging Templates with Mustache Syntax in C#](https://www.textcontrol.com/blog/2024/06/06/mail-merge-merging-templates-with-mustache-syntax-in-csharp/). A class without a project | [MustacheMatcher](https://github.com/TextControl/MustacheMatcher) |
| Parallel merging | Documents merged in separate processes at the same time, as described in [True Parallel Processing of Documents using MailMerge](https://www.textcontrol.com/blog/2019/08/16/true-parallel-processing-of-documents-using-mailmerge/), which says the concept applies to WPF as well. Windows Forms, .NET Framework 4.8, version 30.0 | [TextControl.WindowsForms.Parallel](https://github.com/TextControl/TextControl.WindowsForms.Parallel) |
| DOCVARIABLE fields | DOCVARIABLE fields of MS Word documents converted into merge fields, as described in [Reporting: Merging MS Word Documents with DocVariables](https://www.textcontrol.com/blog/2015/06/10/reporting-merging-ms-word-documents-with-docvariables/). Windows Forms, .NET Framework 4.8, version 34.0 | [TextControl.MailMerge.DocVariables](https://github.com/TextControl/TextControl.MailMerge.DocVariables) |
| Formatted HTML | HTML from the data merged into merge fields with its formatting, as described in [Reporting: Merge Formatted HTML into Merge Fields](https://www.textcontrol.com/blog/2014/02/10/reporting-merge-formatted-html-into-merge-fields/). Windows Forms, .NET Framework 4.0, version 34.0 | [TextControl.MailMerge.MergeFormattedHTML](https://github.com/TextControl/TextControl.MailMerge.MergeFormattedHTML) |
| Events for custom processing | Fields, rows and block rows processed in the merge events, as described in [Reporting: Custom Processing Using MailMerge Events](https://www.textcontrol.com/blog/2014/05/07/reporting-custom-processing-using-mailmerge-events/). Windows Forms, .NET Framework 4.0, version 33.0 | [TextControl.MailMerge.CustomProcessingWithEvents](https://github.com/TextControl/TextControl.MailMerge.CustomProcessingWithEvents) |
| Business objects | Collections of business objects merged into merge blocks and nested merge blocks, with totals calculated in the objects instead of the template, as described in [Advantages of Using Business Objects with Text Control Reporting](https://www.textcontrol.com/blog/2014/05/02/advantages-of-using-business-objects-with-text-control-reporting/). Windows Forms, .NET Framework 4.8, version 33.0 | [TextControl.MailMerge.BusinessObjectsUsage](https://github.com/TextControl/TextControl.MailMerge.BusinessObjectsUsage) |
| Images from files | Image placeholders merged from file names in the data, with the folder of the images set in [SearchPath](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver/mailmerge/searchpath-property/llms-full.txt), as described in [Reporting: Merging Images from Files Using SearchPath](https://www.textcontrol.com/blog/2014/03/12/reporting-merging-images-from-files-using-searchpath/). Windows Forms, .NET Framework 4.0, version 33.0 | [TextControl.MailMerge.MergeImagesFromFiles](https://github.com/TextControl/TextControl.MailMerge.MergeImagesFromFiles) |
| Empty table rows | Alternating row colors from NEXT fields, and empty rows at the end of a merge block removed in `BlockRowMerged`, as described in [Reporting: Removing Empty Table Rows](https://www.textcontrol.com/blog/2014/09/30/reporting-removing-empty-table-rows/). Windows Forms, .NET Framework 4.5, version 33.0 | [TextControl.MailMerge.RemoveEmptyTableRows](https://github.com/TextControl/TextControl.MailMerge.RemoveEmptyTableRows) |

### Blog Articles With Code

| Example | What it shows | Where |
|---|---|---|
| Sorting and filtering | The rows of merge blocks sorted and filtered | [Filtering and Sorting Repeating Blocks in MailMerge using C#](https://www.textcontrol.com/blog/2025/08/21/filtering-and-sorting-repeating-blocks-in-mailmerge-using-csharp/) |
| Calculating business objects | Business objects that calculate their own totals, merged into a template | [Merging Self-Calculating Business Objects with TX Text Control MailMerge in C#](https://www.textcontrol.com/blog/2024/12/27/merging-self-calculating-business-objects-with-tx-text-control-mailmerge-in-csharp/) |
| Merge blocks in code | Merge blocks inserted with the `DataSourceManager` | [Mail Merge: Inserting Merge Blocks using the DataSourceManager in C#](https://www.textcontrol.com/blog/2024/10/02/mail-merge-inserting-merge-blocks-using-the-datasourcemanager-in-csharp/) |

### Next Steps

- [Mail Merge and Reporting](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/llms-full.txt): templates, data sources and merge blocks, explained.
- [TX Words WPF Sample Application](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/tx-words/llms-full.txt): the Reporting sample and the other TX Words samples.
- [PDF Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/pdf/llms-full.txt): merged documents saved as PDF and electronic invoices.

---

## Nearby

- **Previous:** [Document Processing Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/document-processing/llms-full.txt)
- **Next:** [PDF Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/pdf/llms-full.txt)
