TX Text Control .NET for WPF

Rulers and Status Bar

Topic

Rulers for margins, indents and tab stops, and a status bar with the page, line and zoom factor, are what users expect around a document. In a WPF window, the RulerBar and the StatusBar of TX Text Control provide them as XAML elements, and most of their settings are attributes you write next to the element. What follows covers the horizontal and the vertical ruler, their scale and cell references, the areas and labels of the status bar, and showing or hiding the bars.

The bars are placed and connected for the first time in Connect Rulers, Toolbars, and a Status Bar.

The View tab of the WPF TX Words sample with the Toolbars group, whose check boxes show the horizontal ruler, the vertical ruler and the status bar, and the horizontal ruler below the ribbon.

Place and Connect the Bars

The bars are connected by name: the TextControl holds the x:Name of each bar in RulerBar, VerticalRulerBar and StatusBar, and an empty string means that no bar is connected. The same RulerBar class serves as horizontal and vertical ruler: the vertical ruler is the one named in VerticalRulerBar, docked at the left and stretched vertically. Connect the Bars in XAML in the tutorial Connect Rulers, Toolbars, and a Status Bar declares and connects the bars in a DockPanel, and Connecting Ribbon Tabs in XAML shows them in a complete ribbon window.

Ruler Settings

Each property can be written as an attribute in the XAML or set in code:

PropertyValues and effect
ScaleUnitAuto chooses inches or millimeters by the current culture; Inch; Centimeter without millimeter marks; Millimeter, which is centimeters with millimeter marks
EnablePageMarginsTrue lets users set the page margins on the ruler
FormulaModeCell references while the input position is in a table cell: None, the default; Always; Auto, only in cells with a formula; Fixed, relative to the cell where the mode was switched on
BorderStyleColorScheme, Flat, FixedSingle, Simple3D or Fixed3D

FormulaMode shows references in A1 or R1C1 notation according to TextControl.FormulaReferenceStyle, and has no effect with the border styles Simple3D and Fixed3D. Tables and Table Formulas covers formulas.

Unlike the Windows Forms ruler, the WPF RulerBar has no ReadOnly property; to keep users from changing the document, set the EditMode of the TextControl instead.

Status Bar Settings

The StatusBar shows information about the input position and the document in areas that you switch on and off:

PropertyArea
ShowPage, ShowPageCounterThe page of the input position and the number of pages
ShowSection, ShowSectionCounterThe section of the input position and the number of sections
ShowLine, ShowColumnThe line and the column of the input position
ShowLanguageThe language of the selection or the input position
ShowKeyStatesCAPS LOCK, NUM LOCK and insert or overwrite mode
ShowZoom, ShowZoomTrackBarThe zoom factor, as a number or as a track bar that also sets it

The status bar of the WPF TX Words sample with Section 1/1, Page 1/1, Line 1, Column 0, English (United States), NUM and the zoom track bar at 100%.

The reference of the WPF status bar lists a few more properties:

  • Font. FontFamily, FontSize, FontStyle and FontWeight are dependency properties, so they can be set by a style or a binding.
  • A message of your own. Text shows your text until a status of the connected TextControl changes, for example "Document saved" after a save command.

Labels of the Areas

PageText, PageCounterText, SectionText, SectionCounterText, LineText and ColumnText set the labels in front of the values, such as Page:, for example to translate them. BorderStyle takes the values of the ruler and VerticalColorScheme, which the TX Words sample uses.

Configure Both in XAML

The following elements set up a ruler in centimeters with page margins and cell references, and a status bar with sections, key states, a zoom track bar and German labels:

<WPF:RulerBar x:Name="rulerBar" DockPanel.Dock="Top"
              ScaleUnit="Centimeter" EnablePageMargins="True" FormulaMode="Auto"/>
<WPF:StatusBar x:Name="statusBar" DockPanel.Dock="Bottom"
               ShowSection="True" ShowSectionCounter="True"
               ShowKeyStates="True" ShowZoomTrackBar="True"
               PageText="Seite" LineText="Zeile" ColumnText="Spalte"
               SectionText="Abschnitt" BorderStyle="VerticalColorScheme"/>

In code, the enumerations are in the TXTextControl namespace, for example rulerBar.ScaleUnit = TXTextControl.RulerBarScaleUnit.Centimeter; and statusBar.BorderStyle = TXTextControl.StatusBarBorderStyle.VerticalColorScheme;.

Show and Hide the Bars

  • Users, with the ribbon. The Toolbars group of the RibbonViewTab has check boxes for the horizontal ruler, the vertical ruler and the status bar, named TXITEM_HorizontalRuler, TXITEM_VerticalRuler and TXITEM_StatusBar in RibbonViewTab.RibbonItem. Remove them as described in Built-in Ribbon Tabs if the bars should always be visible.
  • Your code. The bars are WPF elements, so verticalRulerBar.Visibility = Visibility.Collapsed; hides the vertical ruler. To detach a bar from the editor instead, set the matching property of the TextControl to an empty string.

The colors of the bars, set with DisplayColors when the border style is ColorScheme, are covered in Styles, Resources, and Themes.

Next Steps