The new WPF version of TX Text Control comes with new data binding possibilities. But Windows Forms offers a similar way of binding properties to data sources or other properties. But the binding is not added in XAML (which is a concept of WPF), but the code itself. But the advantage is still valid: The presentation layer can be abstracted and no additional event handling is required to update the state of specific buttons or menu entries.
The TextControl.InputFormat class is available in the Windows Forms version as well. The properties of this class can be bound to other controls.
The following code shows how to bind a CheckBox that is displayed as a toggle button to the Bold property of the TextControl.InputFormat class:
checkBox1.DataBindings.Add("Checked", textControl1.InputFormat, "Bold", true, DataSourceUpdateMode.OnPropertyChanged);
But what about a ComboBox that should list all available fonts, display the font at the current input position and apply a new font to the selection when the user selects another font in the ComboBox?
First, we can bind the DataSource property of the ComboBox to the GetSupportedFonts method of TX Text Control. This method returns all supported fonts that can be actually used in the document. The Text property of the ComboBox can be bound to the FontFamily property of the TextControl.InputFormat class. And that is all you need to connect the ComboBox to TX Text Control. No event handling, no Selection class.
comboBox1.DataSource = textControl1.GetSupportedFonts(); comboBox1.DataBindings.Add("Text", textControl1.InputFormat, "FontFamily", true, DataSourceUpdateMode.OnPropertyChanged);