Styles, Resources, and Themes
A WPF window gets its look from styles, templates and resources, and the WPF TextControl takes part in this: several of its properties are dependency properties that a Style can set, its template has named parts, and TX Text Control ships value converters for use as resources. The colors of the editor itself are set through a colors object, and the icons of the ribbon are available as images for your own controls. Read on for each of them in turn.
Display Colors of the Editor
DisplayColors takes a TextControlColors object. By default the colors depend on system colors or default values; each property you set replaces one of them, and the properties you leave unset return to their defaults when the object is assigned. The values are System.Windows.Media.Color values:
| Property | Color of |
|---|---|
| DesktopColor | The area around the pages |
| PageBackColor | The page background |
| TextColor, TextBackColor | The text and its background |
| DarkShadowColor, LightShadowColor | The shadows at the right and bottom and at the left and top edges of the pages |
| HeaderFooterLabelColor, HeaderFooterLineColor | The label of an activated header or footer and the line that divides it from the main text |
| FormFieldColor, ActiveFormFieldColor | The highlighting of form fields and of the form field with the input position; Transparent turns it off |
The object can be written directly in XAML, as a property element of the control in MainWindow.xaml:
<WPF:TextControl x:Name="textControl1">
<WPF:TextControl.DisplayColors>
<WPF:TextControlColors DesktopColor="#FF404040"
PageBackColor="White"
FormFieldColor="LightYellow" />
</WPF:TextControl.DisplayColors>
</WPF:TextControl>
The same in code, for example to switch colors while the application runs:
using System.Windows.Media;
using TXTextControl.WPF;
TextControlColors colors = new TextControlColors();
colors.DesktopColor = Color.FromRgb(64, 64, 64);
colors.PageBackColor = Colors.White;
textControl1.DisplayColors = colors;
The rulers and the status bar have display colors of their own, set through WPF.RulerBar.DisplayColors with a RulerBarColors object and through WPF.StatusBar.DisplayColors with a StatusBarColors object. The ruler colors are used only when its BorderStyle is ColorScheme. Rulers and Status Bar covers both bars.
Set Properties in a Style
Many properties of the TextControl, such as BorderThickness, ControlChars and ZoomFactor, are dependency properties, so a Style can set them for every TextControl in its scope. The following style in the resources of the window shows control characters, removes the border and opens every editor at 120 percent:
<Window.Resources>
<Style TargetType="WPF:TextControl">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ControlChars" Value="True" />
<Setter Property="ZoomFactor" Value="120" />
</Style>
</Window.Resources>
What a Style Can Set lists the dependency properties of the TextControl and the bars. DisplayColors is an ordinary .NET property, so it is set on the control or in code, as shown above.
The Template of the TextControl
The TextControl is a System.Windows.Controls.Control with a template of three named parts: a Border, a ScrollViewer and, inside it, the TextControlDocument canvas that shows the document. What TextControlDocument Is lists the parts, and Get the Part in Code finds one with Template.FindName in the Loaded event of the control.
Converters as Resources
TX Text Control provides four value converters, ColorConverter, BooleanConverter, MeasureConverter and LogarithmicConverter, which are declared as resources and used in bindings to the TextControl. Value Converters declares them and shows an example of each.
Resources also define context menus: the spelling menu that SpellCheckContextMenu names is a ContextMenu in the resources of the control or a parent, as Context Menus shows.
The Ribbon
The ribbon tabs of TX Text Control, such as RibbonFormattingTab, derive from System.Windows.Controls.Ribbon.RibbonTab, the tab class of the WPF Ribbon. TX Text Control .NET for WPF has no display colors of its own for the ribbon. Built-in Ribbon Tabs and Connecting Ribbon Tabs in XAML describe how the tabs are placed in a Ribbon.
Icons for Your Own Controls
The static methods of ResourceProvider return the icons, texts, tooltips and key tips of the built-in ribbon tabs and toolbars, as Give Your Buttons the Built-in Icons lists. For the icons, an ImageSourceSettings object recolors the color rectangle of icons such as TXITEM_TextColor with FillColor and StrokeColor, and picks language-specific icons with Culture.
The following code shows the text color icon with a red rectangle in an Image named textColorImage:
private void TextControl1_Loaded(object sender, RoutedEventArgs e)
{
ResourceProvider.ImageSourceSettings settings = new ResourceProvider.ImageSourceSettings();
settings.FillColor = Colors.Red;
// Create the icon in the resolution of the window
textColorImage.Source = ResourceProvider.GetSmallIcon("TXITEM_TextColor", this, settings);
}
It needs using System.Windows.Media; for Colors and using TXTextControl.WPF; for ResourceProvider, and an element such as <Image x:Name="textColorImage" Width="16" Height="16" /> in the window.
Next Steps
- Custom Tabs and Commands: ribbon items with the icons of TX Text Control.
- Rulers and Status Bar: the colors of the rulers and the status bar.
- Localization and Resource Kit: texts and icons in other languages.
- Right-to-Left UI: the flow direction of the window.