# XAML and Data Binding Examples

> Examples of TX Text Control .NET for WPF in XAML: binding buttons to InputFormat, the four value converters, bound undo buttons and the XAML of the samples.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Examples > XAML and Data Binding Examples
- **1130 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/xaml-data-binding/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/xaml-data-binding/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/xaml-data-binding/llms-full.txt

---

WPF controls such as toggle buttons, sliders and text boxes can follow the formatting at the input position of the `TextControl` through data binding, without code-behind. Text Control shows this in a technical article and in the XAML examples of the reference, and the TX Words samples bind their undo buttons this way. No sample project is dedicated to data binding; the examples below are the places where the XAML is shown.

### TextControl in XAML

Every sample of TX Text Control .NET for WPF declares the [TextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/llms-full.txt) in XAML, with a prefix for the namespace `TXTextControl.WPF` such as `WPF` or `my`. The smallest sample that does this is *Simple* in the folder *Tutorial* of [TXSamples\_WPF\_CSharp](https://github.com/TextControl/TXSamples_WPF_CSharp), written for version 32.0. [Add TextControl in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/xaml/#declare-the-namespace) explains the namespace declaration.

### Bind a Button to the Formatting

The technical article on data binding with TX Text Control binds a `ToggleButton` to [InputFormat.Bold](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/bold-property/llms-full.txt), the formatting at the input position: the button shows whether the text at the input position is bold, and clicking it switches bold formatting on or off. [Bind to the Formatting at the Input Position](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/document-content/#bind-to-the-formatting-at-the-input-position) shows this XAML in a complete window and explains each part of the binding. The blog article [Get a Foretaste of What's to Come: WPF Data Binding with TX Text Control](https://www.textcontrol.com/blog/2010/10/11/get-a-foretaste-of-whats-to-come-wpf-data-binding-with-tx-text-control/) shows the same example, together with a style trigger that changes the text of the button.

### Value Converter Examples

Some properties of the `TextControl` have a type or a unit that a WPF control can't show directly. Four value converters of the namespace `TXTextControl.WPF` translate them, and the reference page of each one contains a XAML example:

| Example | What it shows | Where |
|---|---|---|
| Radio buttons for list formats | [BooleanConverter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/booleanconverter/llms-full.txt) checks a radio button when [InputFormat.NumberedListFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/numberedlistformat-property/llms-full.txt) has the value of its converter parameter | [BooleanConverter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/booleanconverter/llms-full.txt) |
| A color swatch | [ColorConverter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/colorconverter/llms-full.txt) converts [InputFormat.TextColor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/textcolor-property/llms-full.txt), a `System.Drawing.Color`, to the color of a WPF brush | [ColorConverter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/colorconverter/llms-full.txt) |
| A zoom slider | [LogarithmicConverter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/logarithmicconverter/llms-full.txt) maps a [ZoomFactor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/zoomfactor-property/llms-full.txt) from 10 to 400 percent to a slider, with 100 percent in the middle | [LogarithmicConverter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/logarithmicconverter/llms-full.txt) |
| A distance in centimeters | [MeasureConverter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/measureconverter/llms-full.txt) shows [InputFormat.TopDistance](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/topdistance-property/llms-full.txt), which is in twips, in a text box in the unit that [Unit](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/measureconverter/unit-property/llms-full.txt) sets | [MeasureConverter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/measureconverter/llms-full.txt) |

[Value Converters](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/value-converters/llms-full.txt) describes the converters and shows their XAML.

### Bindings in the Samples

| Example | What it shows | Where |
|---|---|---|
| Undo and redo buttons | The buttons of the quick access toolbar are enabled through bindings to [CanUndo](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/canundo-property/llms-full.txt) and [CanRedo](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/canredo-property/llms-full.txt) of the `TextControl`. Version 32.0, the .NET Framework 4.8 and .NET 6 | [TXSamples\_WPF\_CSharp](https://github.com/TextControl/TXSamples_WPF_CSharp), the ribbon samples in the folder *TX Words* |

The ribbon tabs of TX Text Control are connected to the `TextControl` in XAML as well; [Ribbon and Sidebar Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/ribbon-sidebar/llms-full.txt) shows how.

### What No Sample Shows

No sample binds the content of a document, such as its text, to a property of your own. [MVVM Integration Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/mvvm/#what-you-can-build-on) says why, and [Binding Document Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/document-content/llms-full.txt) covers the content of a document and your data.

### Next Steps

- [Data Binding](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/llms-full.txt): how data binding works with the `TextControl`.
- [MVVM Integration Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/mvvm/llms-full.txt): the building blocks for an MVVM application.
- [XAML Integration](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/xaml/llms-full.txt): declare and configure the controls in XAML.

---

## Nearby

- **Previous:** [Ribbon and Sidebar Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/ribbon-sidebar/llms-full.txt)
- **Next:** [MVVM Integration Examples](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/examples/mvvm/llms-full.txt)
