TX Text Control .NET for WPF

Assemblies and XAML Namespaces

Topic

XAML knows nothing about TX Text Control until a window maps a prefix to a .NET namespace in an assembly: only then does <WPF:TextControl /> name a real class. TX Text Control .NET for WPF 34.0 consists of a dozen assemblies, and its classes are spread over several namespaces. The tables below show which assembly holds which namespace, how a window declares the namespace of the controls and which using directives the code-behind needs, so you can read the declarations Visual Studio writes and write your own.

The Assemblies

The NuGet package TXTextControl.TextControl.WPF.SDK brings the same managed assemblies into a .NET project, in its folder lib/net8.0, that the setup installs in the Assembly folder for .NET Framework projects:

AssemblyNamespacesWhat it contains
TXTextControl.WPF.dllTXTextControl.WPFThe WPF controls: TextControl, the bars, the ribbon tabs, Sidebar, the dialog boxes and the value converters
TXTextControl.dllTXTextControl, TXTextControl.DataVisualizationThe document object model that the editor and the engine share, such as Selection and VersionInfo, and the chart frames such as ChartFrame
TXTextControl.Server.dllTXTextControlServerTextControl, the document engine without a user interface
TXDocumentServer.dllTXTextControl.DocumentServer and the namespaces below it, such as TXTextControl.DocumentServer.Fields and TXTextControl.DocumentServer.DataSourcesMailMerge, the field classes such as DateField, and DataSourceManager
TXDocumentServer.WPF.dllTXTextControl.DocumentServer.WPFThe WPF dialog boxes for merge blocks, such as FilterAndSortDialog
TXDrawing.dll, TXDrawing.WPF.dllTXTextControl.Drawing, TXTextControl.WPF.DrawingShapes and drawings, with TXDrawingControl for WPF
TXBarcode.dll, TXBarcode.WPF.dllTXTextControl.Barcode, TXTextControl.WPF.BarcodeBarcodes, with TXBarcodeControl for WPF
TXImageProvider.dll, TXSVGResources.dll, txpdf.dllSupporting assemblies of the engine

Beside them are the German resources, in the subfolder de, and the native libraries for 32-bit and 64-bit Windows, which 32-bit and 64-bit Applications describes. Your application deploys all of these files; see Managed Assemblies and Native Libraries.

In a .NET project, the package references every assembly for you. In a .NET Framework project, Visual Studio adds the reference to TXTextControl.WPF when you place the first control from the toolbox, and you add references to the other assemblies of the Assembly folder that your code uses, such as TXTextControl.dll for Selection or TXDocumentServer.dll for MailMerge.

Declare the Namespace of the Controls in XAML

A WPF window declares the namespace of the controls in its root element with a clr-namespace mapping. When you add the first control from the toolbox, Visual Studio writes the declaration with the prefix WPF:

The XAML editor of Visual Studio showing a Window element with the declaration xmlns:WPF="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF" and five controls with the prefix WPF in a DockPanel.

Written by hand, a complete window with the editor looks like this:

<Window x:Class="MyWpfApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WPF="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
        Title="MainWindow" Height="450" Width="800">
    <DockPanel>
        <WPF:TextControl x:Name="textControl1" />
    </DockPanel>
</Window>

The declaration works as follows:

  • xmlns:WPF defines the prefix. The name is yours to choose: this documentation and the samples of Text Control use WPF, and the Simple sample uses my. Every element of the window uses the prefix its root element declares.
  • clr-namespace:TXTextControl.WPF is the .NET namespace of the controls.
  • assembly=TXTextControl.WPF is the name of the assembly, without .dll. The project must reference it, through the package or directly.

All toolbox items of TX Text Control are in this one namespace, so a window with the editor, its bars, sidebars and ribbon tabs needs only this declaration. The Ribbon that hosts the ribbon tabs is part of WPF and needs no prefix.

Declare Further Namespaces

The other namespaces rarely appear in XAML, because drawings, barcodes and the merge block dialog boxes are created in code. When a window does need one, it declares it the same way, with the assembly from the table above:

xmlns:WPF="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
xmlns:txdrawing="clr-namespace:TXTextControl.WPF.Drawing;assembly=TXDrawing.WPF"
xmlns:txbarcode="clr-namespace:TXTextControl.WPF.Barcode;assembly=TXBarcode.WPF"
xmlns:txmerge="clr-namespace:TXTextControl.DocumentServer.WPF;assembly=TXDocumentServer.WPF"
xmlns:txtextcontrol="clr-namespace:TXTextControl;assembly=TXTextControl"

A namespace can be spread over several assemblies: TXTextControl is in TXTextControl.dll and in TXTextControl.Server.dll. A clr-namespace mapping names one assembly, so it finds only the classes of that assembly, and a class in the other one needs a second declaration with its own prefix.

TX Spell .NET for WPF, the spell checker for TX Text Control, adds its own namespace, TXTextControl.WPF.Proofing in the assembly TXSpell.WPF. See Integrating TX Spell .NET for WPF.

Use the Namespaces in Code-Behind

In MainWindow.xaml.cs, the field that XAML generates for textControl1 already has its full type, TXTextControl.WPF.TextControl. The classes you reach through it, and the classes you create yourself, need using directives for their namespaces:

using System.Windows;
using TXTextControl;
using TXTextControl.DocumentServer;

namespace MyWpfApp;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void textControl1_Loaded(object sender, RoutedEventArgs e)
    {
        // Selection is in the namespace TXTextControl, in TXTextControl.dll
        textControl1.Selection.Bold = true;

        // MailMerge is in TXTextControl.DocumentServer, in TXDocumentServer.dll
        using (MailMerge mailMerge = new MailMerge())
        {
            mailMerge.TextComponent = textControl1;
        }
    }
}

The code works as follows:

  • using TXTextControl; makes the shared document classes available, such as the Selection that TextControl.Selection returns. Bold formats the selected text.
  • using TXTextControl.DocumentServer; makes MailMerge available. TextComponent connects it to the editor.
  • The handler runs for Loaded="textControl1_Loaded" on the TextControl element, once the control is ready to be used.

Add using TXTextControl.WPF; when the code-behind creates WPF controls of TX Text Control itself; Creating and Configuring Controls in Code shows how.