# Data Binding

> Which TextControl properties are binding targets, why InputFormat and CanUndo are sources, and how bars, the document and converters fit into WPF bindings.

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

---

Data binding is how WPF connects controls to data without event handlers, and the `TextControl` takes part in it on both sides: some of its properties can be set by a binding, and many of its values can feed one. Knowing which is which tells you how toolbars and view models bind to the editor, and what to do where no binding exists, such as for the document content.

### How Binding Works With the TextControl

A WPF binding has a target, which must be a dependency property, and a source, which can be any property. For the `TextControl`, this means:

- **The editor as a target.** A view model or another control can set the dependency properties of the [TextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/llms-full.txt) through a binding, such as [ZoomFactor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/zoomfactor-property/llms-full.txt), [ViewMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/viewmode-property/llms-full.txt) and [IsUndoEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/isundoenabled-property/llms-full.txt). [What a Style Can Set](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/styling/#what-a-style-can-set) lists all of them.
- **The editor as a source.** Every property can feed a binding. The most useful source is [InputFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/inputformat/llms-full.txt), the formatting at the input position, which updates itself when the caret moves. [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) enable buttons.
- **Properties that are not dependency properties,** such as [EditMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/editmode-property/llms-full.txt), [DisplayColors](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/displaycolors-property/llms-full.txt) and [Text](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/text-property/llms-full.txt), are set in XAML or in code, not by a binding.
- **Connections to the bars are names, not bindings.** `ButtonBar="buttonBar1"`, `RulerBar`, `StatusBar` and the ribbon tab properties take the name of the other control as a string.
- **The document has no bindable property.** Its content moves in and out with `Load` and `Save`; an attached property of your own can wrap them for a binding.

Values in twips, `System.Drawing.Color` values and enumeration values reach WPF controls through the value converters of TX Text Control.

The `Mode` of a binding decides in which direction the value flows. A toggle button bound to `InputFormat.Bold` needs `TwoWay`, because its click has to change the text:

| Mode | The value flows |
|---|---|
| `OneWay` | From the source to the target, whenever the source changes |
| `TwoWay` | In both directions, whenever the source or the target changes |
| `OneTime` | From the source to the target once, when the binding starts |
| `OneWayToSource` | From the target to the source, whenever the target changes |

### Find the Right Page

| If you want to | Read |
|---|---|
| Bind toolbar controls to the formatting at the input position | [Binding Document Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/document-content/#bind-to-the-formatting-at-the-input-position) |
| Bind the whole document to a property of a view model | [Binding Document Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/document-content/#bind-the-whole-document) |
| Show font sizes in points, colors in a swatch or a zoom slider | [Value Converters](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/value-converters/llms-full.txt) |
| Reach the element of the template that shows the document | [TextControlDocument](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/textcontroldocument/llms-full.txt) |
| Structure the application with a view model and commands | [MVVM Integration Patterns](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/mvvm/llms-full.txt) |
| Find out why a binding doesn't work | [Data Binding and Commands](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/data-binding/llms-full.txt) in Troubleshooting |

### Pages in This Section

- [TextControlDocument](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/textcontroldocument/llms-full.txt): the `Canvas` in the template of the `TextControl` that shows the document, and how to get it.
- [Binding Document Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/document-content/llms-full.txt): bindings to `InputFormat` and `CanUndo`, and an attached property that binds the whole document.
- [Value Converters](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/value-converters/llms-full.txt): `MeasureConverter`, `ColorConverter`, `BooleanConverter` and `LogarithmicConverter` in bindings.

---

## In This Section

- [Binding Document Content](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/document-content/llms-full.txt): Bind WPF toolbars to InputFormat and CanUndo in XAML, and bind the whole document to a view model byte array with an attached property using Load and Save.
- [TextControlDocument](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/textcontroldocument/llms-full.txt): Get the TXPART_Document canvas of the WPF TextControl with Template.FindName or OnApplyTemplate, bind to its size and convert positions with PointToDocument.
- [Value Converters](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/value-converters/llms-full.txt): Use MeasureConverter, ColorConverter, BooleanConverter and LogarithmicConverter to show twips in points, text colors, list formats and a zoom slider in WPF.

---

## Nearby

- **Previous:** [Control Initialization and Document Access](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/initialization/llms-full.txt)
- **Next:** [TextControlDocument](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/textcontroldocument/llms-full.txt)
