# Reporting Ribbon and WPF Dialog Boxes

> The WPF RibbonReportingTab: its groups, the Field Navigation sidebar in XAML, the DocumentServer.WPF dialog windows, FieldAdapter.ShowDialog and FindName.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Mail Merge and Reporting > Reporting Ribbon and WPF Dialog Boxes
- **3475 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/ribbon-dialogs/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/ribbon-dialogs/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/ribbon-dialogs/llms-full.txt

---

With the **Reporting** tab in its ribbon, the `TextControl` of a WPF window becomes a template designer: users load a data source, insert merge fields, special fields and merge blocks and set their options in dialog boxes. The WPF tab is a class of its own, and it differs from the Windows Forms tab in a few groups and dialog boxes. Below you find each group and dialog box of the WPF tab, the classes that open the dialog boxes from your code and how to hide buttons with `FindName`.

The tutorial [Create a Template](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/mail-merge/template/llms-full.txt) adds the tab in XAML and inserts the first merge fields. [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/fields/llms-full.txt), [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/blocks/llms-full.txt) and [Data Sources](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/data-sources/llms-full.txt) explain what the tab inserts and loads.

### The Reporting Tab

[RibbonReportingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonreportingtab/llms-full.txt) derives from `System.Windows.Controls.Ribbon.RibbonTab` and is placed inside the `Ribbon` element of *MainWindow.xaml*. The `TextControl` names it in its [RibbonReportingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ribbonreportingtab-property/llms-full.txt) attribute, which connects the two; [Add the Reporting Tab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/mail-merge/template/#add-the-reporting-tab) shows the XAML, and [Connecting Ribbon Tabs in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/ribbon-xaml/llms-full.txt) explains this pattern for all tabs. The tab has four groups:

![The Reporting tab of the WPF ribbon with the groups Data Source, Merge Fields, Merge Blocks and View](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/ribbon-reporting-tab.e14e49fb.webp)

| Group | Buttons | What they do |
|---|---|---|
| **Data Source** | **Select Data Source**, **Select Master Table**, **Edit Data Relations** | Load the data whose names the tab offers, choose the master table and relate tables |
| **Merge Fields** | **Insert Merge Field**, **Insert Special Field**, **Field Properties**, **Delete Field** | Insert and edit merge fields and the special fields `IF`, `INCLUDETEXT`, `DATE`, `NEXT` and `NEXTIF` |
| **Merge Blocks** | **Insert Merge Block**, **Edit Merge Block** | Insert repeating blocks, rename and remove them |
| **View** | **Field Navigation** | Show the fields and blocks of the document in a sidebar |

Compared with Windows Forms, the WPF tab has no **Config File** button, and **Select Data Source** doesn't connect to databases: data source configuration files and database connections of the designer are Windows Forms features.

### Data Source

The data source provides the names that the drop-down menus of the tab offer. It serves the design only; at merge time, any data with the same structure fills the template. **Select Data Source** has three commands:

![The Select Data Source drop-down of the WPF Reporting tab with the commands Load XML File, Load Assembly and Load JSON File](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/select-data-source-menu.4d9e5600.webp)

**Load XML File**, **Load Assembly** and **Load JSON File** load an XML file, the public classes of a .NET assembly or a JSON file. Your code loads data with the tab's `DataSourceManager`, for example in the `Loaded` event of the window, as [Create a Template](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/mail-merge/template/#load-the-sample-data-into-the-tab) shows.

**Select Master Table** lists the tables of the loaded data. The master table supplies the merge fields outside blocks, and the tables related to it are offered as merge blocks. **Edit Data Relations** opens a dialog box that relates two tables by a column.

### Merge Fields

**Insert Merge Field** lists the columns of the master table. Related tables appear as submenus, and a field inserted from a submenu gets the name of its table as a prefix, such as `Production_Product.Name`. The last two entries are **Insert Custom Merge Field...** and **Highlight Merge Fields**, which marks all merge fields in the document.

**Insert Special Field** inserts fields that aren't filled from a column directly: an `IF` field that inserts one of two texts, an `INCLUDETEXT` field that includes a subtemplate, a `DATE` field with the current date, and the `NEXT` and `NEXTIF` fields that continue with the next record. `IF` and `INCLUDETEXT` fields are inserted through their options dialog box, which **Field Properties** opens again later.

For a merge field, **Field Properties** opens the **Merge Field Options** dialog box with the name, the text before and after the value, the letter case and the number and date formats, as [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/fields/llms-full.txt) describes. [Conditional Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/conditional-content/llms-full.txt) and [Subtemplates](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/subtemplates/llms-full.txt) cover the `IF` and `INCLUDETEXT` fields. **Delete Field** removes the field at the input position.

### Merge Blocks

**Insert Merge Block** lists the tables related to the master table:

![The Insert Merge Block drop-down of the WPF Reporting tab with three tables below the Tables heading and the entries Insert Custom Merge Block and Highlight Merge Blocks](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/insert-merge-block-menu.443672cc.webp)

A table opens the **Insert Merge Block** dialog box. In it, the user checks the columns that become merge fields and sets their order, chooses between a table row, optionally with a header row, and a plain paragraph, picks the highlight color of the block and adds filter and sorting rules. [Merge Blocks](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/blocks/#check-the-result-of-the-dialog-box) reads what the user inserted, and [Sorting and Filtering](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/sorting-filtering/llms-full.txt) explains the rules.

**Insert Custom Merge Block** makes the selected text a block with a name of the user's choice. **Highlight Merge Blocks** marks all blocks of the document. **Edit Merge Block** opens a dialog box that renames or removes merge blocks.

### Show the Field Navigation Sidebar

**Field Navigation** in the **View** group opens a panel with the tabs **Merge Blocks** and **Merge Fields**, a search box and the properties of the selected element:

![The Field Navigation sidebar of the WPF Reporting tab with a merge block and its fields on the Merge Blocks tab](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/field-navigation-sidebar.52e7010c.webp)

The button stays hidden until a sidebar is connected. In WPF, [FieldNavigatorSidebar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonreportingtab/fieldnavigatorsidebar-property/llms-full.txt) is a string: the name of a [Sidebar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/sidebar/llms-full.txt) element of the window, set in XAML as [Show the Field Navigation Sidebar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/mail-merge/template/#show-the-field-navigation-sidebar) in Getting Started shows. [Sidebar and Panels](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/sidebar/llms-full.txt) describes sidebars.

### Dialog Classes

The dialog boxes for blocks and data relations are WPF windows, derived from `System.Windows.Window`, in the namespace `TXTextControl.DocumentServer.WPF`. The field options dialog boxes open through the field classes of `TXTextControl.DocumentServer.Fields`:

| Dialog box | Opened by | Class or method |
|---|---|---|
| **Merge Field Options** and the options of `IF`, `INCLUDETEXT` and `DATE` fields | **Field Properties** | [FieldAdapter.ShowDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/fieldadapter/showdialog-method/llms-full.txt) of `MergeField`, `IfField`, `IncludeText` and `DateField` |
| **Insert Merge Block** | **Insert Merge Block** | [InsertMergeBlockDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-wpf/insertmergeblockdialog/llms-full.txt) |
| Filter and sorting rules | The **Insert Merge Block** dialog box | [FilterAndSortDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-wpf/filterandsortdialog/llms-full.txt) |
| Rename and remove blocks | **Edit Merge Block** | [EditMergeBlocksDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-wpf/editmergeblocksdialog/llms-full.txt) |
| Data relations | **Edit Data Relations** | [EditDataRelationsDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-wpf/editdatarelationsdialog/llms-full.txt) |

The windows are modal and shown with `ShowDialog`. Their constructors take the [DataSourceManager](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonreportingtab/datasourcemanager-property/llms-full.txt) of the tab and, where they change the document, the `TextControl`.

### Open the Dialog Boxes From Code

The following handlers of *MainWindow.xaml.cs* open the options of the field at the input position and the dialog box for merge blocks. Connect them to buttons with `Click="fieldOptionsButton_Click"` and so on:

```csharp
using System.Windows;
using TXTextControl;
using TXTextControl.DocumentServer.Fields;
using TXTextControl.DocumentServer.WPF;
```

```csharp
private void fieldOptionsButton_Click(object sender, RoutedEventArgs e)
{
    // The field at the input position, or null
    ApplicationField applicationField = textControl1.ApplicationFields.GetItem();

    if (applicationField == null)
    {
        return;
    }

    FieldAdapter fieldAdapter;

    switch (applicationField.TypeName)
    {
        case "MERGEFIELD": fieldAdapter = new MergeField(applicationField); break;
        case "IF": fieldAdapter = new IfField(applicationField); break;
        case "INCLUDETEXT": fieldAdapter = new IncludeText(applicationField); break;
        case "DATE": fieldAdapter = new DateField(applicationField); break;
        default: return;
    }

    // The window owns the dialog box
    fieldAdapter.ShowDialog(this);
}

private void editBlocksButton_Click(object sender, RoutedEventArgs e)
{
    EditMergeBlocksDialog dialog = new EditMergeBlocksDialog(
        ribbonReportingTab1.DataSourceManager, textControl1)
    {
        Owner = this
    };

    dialog.ShowDialog();
}
```

The code works as follows:

- [ApplicationFields.GetItem](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/applicationfieldcollection/getitem-method/llms-full.txt) returns the field at the input position, and its [TypeName](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/applicationfield/typename-property/llms-full.txt) selects the field class: [MergeField](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/mergefield/llms-full.txt), [IfField](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/iffield/llms-full.txt), [IncludeText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/includetext/llms-full.txt) or [DateField](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/datefield/llms-full.txt). For WPF dialog boxes, the owner passed to `ShowDialog` must be a `System.Windows.Window`, here the main window.
- `EditMergeBlocksDialog` is a WPF window: it gets its owner through the `Owner` property of `Window` and takes the `DataSourceManager` of the tab and the `TextControl` whose blocks it lists.

`FilterAndSortDialog`, the window for the filter and sorting rules of a block, is opened for the block at the input position in [Sorting and Filtering](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/sorting-filtering/#let-users-edit-the-instructions).

### Hide Buttons of the Tab

Every item of the WPF tab has a name from the [RibbonReportingTab.RibbonItem](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonreportingtab/ribbonitem-enumeration/llms-full.txt) enumeration, and `FindName` of the tab returns the item of that name. There is no `FindItem` method as in Windows Forms. The following handler of the window's `Loaded` event, `Loaded="Window_Loaded"` in XAML, hides **Edit Data Relations**:

```csharp
using System.Windows;
using TXTextControl.WPF;
```

```csharp
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    // Hide the Edit Data Relations button
    if (ribbonReportingTab1.FindName(
        RibbonReportingTab.RibbonItem.TXITEM_EditDataRelations.ToString()) is UIElement item)
    {
        item.Visibility = Visibility.Collapsed;
    }
}
```

The string of a `RibbonItem` value is the `Name` of the item, so `ToString()` gives the name `FindName` looks for. Group names end in `Group`, such as `TXITEM_DataSourceGroup`. The entries of drop-down menus are values of [RibbonReportingTab.RibbonDropDownItem](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonreportingtab/ribbondropdownitem-enumeration/llms-full.txt), which identify their texts and icons for the resource provider. [Built-in Ribbon Tabs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/ribbon/llms-full.txt) covers the items of the other tabs.

### Next Steps

- [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-design/llms-full.txt): where and with which data users design templates.
- [Template Preview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-preview/llms-full.txt): merge the template with the data of the tab.
- [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/fields/llms-full.txt): the options of the Merge Field Options dialog box in code.
- [Built-in Dialog Boxes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/dialog-boxes/llms-full.txt): the other dialog boxes of the editor.

---

## Nearby

- **Previous:** [Template Design](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-design/llms-full.txt)
- **Next:** [Template Preview](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/template-preview/llms-full.txt)
