# XAML Integration

> Declare TextControl, ribbon tabs, bars and Sidebar in XAML with the WPF prefix: connections by name, property elements, event attributes and the XAML Designer.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Integration Guide > XAML Integration
- **2692 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/xaml/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/xaml/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/xaml/llms-full.txt

---

A WPF window with TX Text Control is mostly XAML: the editor, its ribbon tabs, bars and sidebars are elements, their settings are attributes, and they find each other by name. Knowing the few kinds of XAML entries the product uses lets you read what the toolbox writes, write a window by hand and spot a connection that doesn't work. Each kind is shown below, then all of them together in one window.

If you haven't placed a `TextControl` in XAML yet, [Add TextControl in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/xaml/llms-full.txt) starts with the minimal window.

### The Kinds of XAML Entries

| Entry | Example | Used for |
|---|---|---|
| Namespace declaration | `xmlns:WPF="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"` | Mapping the prefix `WPF` to the controls of TX Text Control |
| Element | `<WPF:TextControl x:Name="textControl1" />` | The editor, the bars, the ribbon tabs and the sidebars |
| Attribute | `ViewMode="PageView"` | Properties with simple values, such as enumeration values, numbers and strings |
| Connection by name | `StatusBar="statusBar1"` | Connecting the editor to a bar, a ribbon tab or a sidebar |
| Property element | `<WPF:TextControl.DisplayColors>` | Properties whose value is an object, such as [TextControlColors](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrolcolors/llms-full.txt) |
| Event attribute | `Loaded="textControl1_Loaded"` | Handlers in the code-behind, for WPF events and events of TX Text Control |
| Resource | `<spell:TXSpellChecker x:Key="txSpellChecker1" />` | Objects that aren't shown, such as the spell checker of TX Spell .NET |

All controls of TX Text Control are in the namespace `TXTextControl.WPF` of the assembly *TXTextControl.WPF*, so one declaration covers the whole window. The Visual Studio toolbox writes it with the prefix `WPF`, and the samples here use the same prefix. [Assemblies and XAML Namespaces](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/installation/xaml-namespaces/llms-full.txt) lists the other namespaces, such as those for drawings and barcodes.

### Connections Are Names

The WPF controls of TX Text Control don't hold references to each other. Each connection property is a string with the `x:Name` of the element it connects to, and an empty string, the default, means that nothing is connected:

- **The `TextControl`** names its bars in [ButtonBar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/buttonbar-property/llms-full.txt), [RulerBar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/rulerbar-property/llms-full.txt), [VerticalRulerBar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/verticalrulerbar-property/llms-full.txt) and [StatusBar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/statusbar-property/llms-full.txt), and each ribbon tab in a property of the same name, such as [RibbonFormattingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ribbonformattingtab-property/llms-full.txt) and [RibbonInsertTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ribboninserttab-property/llms-full.txt).
- **A [Sidebar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/sidebar/llms-full.txt)** names its editor in its own [TextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/sidebar/textcontrol-property/llms-full.txt) property.
- **A ribbon tab** names the sidebars its buttons open, for example in [StylesSidebar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonformattingtab/stylessidebar-property/llms-full.txt) of the [RibbonFormattingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonformattingtab/llms-full.txt).
- **The spell checker** is connected through [SpellChecker](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/spellchecker-property/llms-full.txt), which holds the key of a resource, not the name of an element; see [Integrating TX Spell .NET for WPF](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/tx-spell/llms-full.txt).

Because they are plain strings, write the names without `{Binding}` or `{StaticResource}`. The compiler doesn't check them: a misspelled name leaves the bar unconnected without an error, and renaming an element in the XAML means updating every property that names it. Keep the connected elements in the same window or user control as the `TextControl`, where their names are defined.

### A Complete Window

The following *MainWindow.xaml* uses every kind of entry: a ribbon with two tabs, a ruler, a status bar, a styles sidebar connected to the **Home** tab, and the editor in page view on a light gray background:

```xml
<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="600" Width="1000">
    <DockPanel>
        <!-- The ribbon is a WPF control; the tabs come from TX Text Control -->
        <Ribbon x:Name="ribbon1" DockPanel.Dock="Top">
            <WPF:RibbonFormattingTab x:Name="ribbonFormattingTab1"
                                     StylesSidebar="stylesSidebar1" />
            <WPF:RibbonInsertTab x:Name="ribbonInsertTab1" />
        </Ribbon>

        <WPF:StatusBar x:Name="statusBar1" DockPanel.Dock="Bottom" />
        <WPF:RulerBar x:Name="rulerBar1" DockPanel.Dock="Top" />

        <!-- A sidebar names its editor, too -->
        <WPF:Sidebar x:Name="stylesSidebar1" DockPanel.Dock="Right" Width="250"
                     ContentLayout="Styles" TextControl="textControl1" />

        <WPF:TextControl x:Name="textControl1"
                         RibbonFormattingTab="ribbonFormattingTab1"
                         RibbonInsertTab="ribbonInsertTab1"
                         RulerBar="rulerBar1"
                         StatusBar="statusBar1"
                         ViewMode="PageView"
                         Loaded="textControl1_Loaded"
                         Changed="textControl1_Changed">
            <WPF:TextControl.DisplayColors>
                <WPF:TextControlColors DesktopColor="#F5F6F7" />
            </WPF:TextControl.DisplayColors>
        </WPF:TextControl>
    </DockPanel>
</Window>
```

The XAML works as follows:

- **`Ribbon`** has no prefix: it is the ribbon of WPF, in `System.Windows.Controls.Ribbon`. The tabs inside it, [RibbonFormattingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribbonformattingtab/llms-full.txt) and [RibbonInsertTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/ribboninserttab/llms-full.txt), are predefined tabs of TX Text Control, which the `TextControl` finds by their names.
- **`DockPanel.Dock`** is an attached property of the WPF `DockPanel`: the ribbon and the ruler go to the top, the status bar to the bottom, the sidebar to the right, and the `TextControl`, the last child, fills the rest. [WPF Layout and Resizing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/layout/llms-full.txt) covers other panels.
- **`ContentLayout="Styles"`** chooses the panel of the sidebar; XAML converts the text into the value of the enumeration, as for `ViewMode="PageView"`. `StylesSidebar="stylesSidebar1"` connects the sidebar to the **Change Styles** item of the style list on the **Home** tab.
- **`WPF:TextControl.DisplayColors`**, the property element, and the event attributes **`Loaded`** and **`Changed`** work as in [Set Properties and Events in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/xaml/#set-properties-and-events-in-xaml), and the two handlers are the methods of [Handle the Events in the Code-Behind](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/xaml/#handle-the-events-in-the-code-behind), in *MainWindow.xaml.cs*.

The ribbon tabs are part of the Enterprise and Professional editions; see [Editions and Feature Availability](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/editions/llms-full.txt).

### What XAML Can't Set

Some members of the `TextControl` exist only at run time, because they describe the document rather than the control: [Selection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/selection-property/llms-full.txt), the collections such as `Tables`, `Images` and `Barcodes`, and state such as `CanUndo`. The reference marks them "Runtime only". Use them in code, once the control is loaded; [Control Initialization and Document Access](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/initialization/llms-full.txt) explains when that is. Document content, such as a template the editor starts with, is loaded in code as well, or bound through the data binding support of TX Text Control; see [Data Binding](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/llms-full.txt).

### The XAML Designer

The XAML Designer of Visual Studio shows the window as you edit the XAML, once the project has been built. In its **Properties** window, the connection properties of a selected `TextControl` are text boxes into which you type the name of the bar or tab. [Visual Studio Toolbox and XAML Designer](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/installation/toolbox/llms-full.txt) describes the toolbox, the designer and the restart it asks for when the first control is added, and [Toolbox and XAML Designer](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/toolbox/llms-full.txt) in Troubleshooting what to do when a bar isn't connected.

### Next Steps

- [Creating and Configuring Controls in Code](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/controls-in-code/llms-full.txt): the same window, created in code.
- [Connecting Ribbon Tabs in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/ribbon-xaml/llms-full.txt): all ribbon tabs, contextual tabs and sidebars.
- [Resource Dictionaries and Styling](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/styling/llms-full.txt): styles and resources for the controls.
- [Data Binding](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/llms-full.txt): bind properties and document content to view models.

---

## Nearby

- **Previous:** [Integration Guide](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/llms-full.txt)
- **Next:** [Creating and Configuring Controls in Code](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/controls-in-code/llms-full.txt)
