HypernovaDesktop Components · docs
Binarymission
WPF › Ribbon › BinaryRibbonSmartTextBox

BinaryRibbonSmartTextBox

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WPF.Controls.Office

A ribbon text box with a watermark prompt while it is empty, a button that clears it, an optional filter on what can be typed, and a small flag picture that changes when the box is left empty – for search boxes, quick filters and required fields on the ribbon.

public class BinaryRibbonSmartTextBox : TextBox, IBinaryRibbonKeyTipControl

Inherits from / implements: TextBox, IBinaryRibbonKeyTipControl

Remarks

It is a WPF TextBox, so TextBox.Text and TextChanged work as usual.

Watermark

WatermarkContent – "Search orders", say – is shown in grey while the box is empty and does not have the keyboard focus. WatermarkContentTemplate draws it.

Clear button

A button at the right-hand end (ClearTextVisualContent, " X " unless changed) empties the box. With the default settings it appears as soon as there is text and goes when the box is empty; see IsClearTextVisualRenderingFeatureEnabled and IsClearTextVisualAlwaysVisible.

What can be typed

DataEntryMode and DisallowedInputRegularExpression filter characters as they are typed. Text that is pasted, or set in code, is not filtered.

Flag picture

A 12 x 12 picture at the top right of the box can show AlertClueImageSourceOnError while the box is empty and AlertClueImageSource once something has been typed – a red flag that turns green, for a required field – with AlertFlagTooltipContent as its tooltip.

Appearance

The frame is drawn with ControlBorderBrush, not Control.BorderBrush. The fill and text colours come from the ribbon's skin. The box is hidden when its group folds into a drop-down.

Examples

A search box on the ribbon that filters an order list as the user types.

<ribbon:BinaryRibbonGroup TitleText="Find"
        xmlns:ribbon="clr-namespace:Binarymission.WPF.Controls.Office;assembly=Binarymission.WPF.Controls.BinaryRibbon">
    <ribbon:BinaryRibbonSmartTextBox x:Name="orderSearch"
                                     Width="180"
                                     WatermarkContent="Search orders"
                                     ControlBorderBrush="#FFABADB3"
                                     TextChanged="OnOrderSearchChanged" />
</ribbon:BinaryRibbonGroup>
private void OnOrderSearchChanged(object sender, TextChangedEventArgs e)
{
    string text = orderSearch.Text ?? string.Empty;
    ordersView.Filter = row => ((Order)row).Customer.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0;
}

See also

Members at a glance

Constructors
BinaryRibbonSmartTextBoxCreates an empty smart text box, with the clear button turned on and no watermark.
Properties
AlertClueImageSourceGets or sets the flag picture shown once the box has text in it – the "all is well" state of a required field.
AlertClueImageSourceOnErrorGets or sets the flag picture shown while the box is empty – the "needs attention" state of a required field.
AlertFlagTooltipContentGets or sets the tooltip shown over the flag picture – "Customer reference is required", say.
ClearTextVisualContentGets or sets what the clear button shows.
ClearTextVisualForegroundBrushGets or sets the colour of the clear button's content while the button is disabled.
ClearTextVisualOnHoverForegroundBrushGets or sets the colour of the clear button's content while the pointer is over it.
ControlBorderBrushGets or sets the colour of the box's frame.
DataEntryModeGets or sets which characters the user can type into the box.
DisallowedInputRegularExpressionGets or sets a regular expression for the characters the user may not type, when DataEntryMode is DataEntryMode.None.
IsAlertClueImageRenderingEnabledGets or sets whether the flag picture changes between AlertClueImageSourceOnError and AlertClueImageSource as the box is emptied and filled.
IsClearTextVisualAlwaysVisibleGets or sets whether the clear button is on show before anything has been typed.
IsClearTextVisualRenderingFeatureEnabledGets or sets whether the clear button comes and goes with the text: shown while there is text, hidden while there is none.
WatermarkContentGets or sets the prompt shown in the box while it is empty and does not have the keyboard focus – "Search orders", "Customer name".
WatermarkContentTemplateGets or sets the template that draws WatermarkContent.
Methods
OnApplyTemplateFinds the parts of the new template – the clear button PART_ClearTextVisual, the flag PART_AlertClueImage, the text host PART_ContentHost and the watermark PART_WatermarkContent – and puts the watermark and flag in their starting state.
Fields
AlertClueImageSourceOnErrorPropertyIdentifies the AlertClueImageSourceOnError dependency property.
AlertClueImageSourcePropertyIdentifies the AlertClueImageSource dependency property.
AlertFlagTooltipContentPropertyIdentifies the AlertFlagTooltipContent dependency property.
ClearTextVisualContentPropertyIdentifies the ClearTextVisualContent dependency property.
ClearTextVisualForegroundBrushPropertyIdentifies the ClearTextVisualForegroundBrush dependency property.
ClearTextVisualOnHoverForegroundBrushPropertyIdentifies the ClearTextVisualOnHoverForegroundBrush dependency property.
ControlBorderBrushPropertyIdentifies the ControlBorderBrush dependency property.
DataEntryModePropertyIdentifies the DataEntryMode dependency property.
DisallowedInputRegularExpressionPropertyIdentifies the DisallowedInputRegularExpression dependency property.
IsAlertClueImageRenderingEnabledPropertyIdentifies the IsAlertClueImageRenderingEnabled dependency property.
IsClearTextVisualAlwaysVisiblePropertyIdentifies the IsClearTextVisualAlwaysVisible dependency property.
IsClearTextVisualRenderingFeatureEnabledPropertyIdentifies the IsClearTextVisualRenderingFeatureEnabled dependency property.
WatermarkContentPropertyIdentifies the WatermarkContent dependency property.
WatermarkContentTemplatePropertyIdentifies the WatermarkContentTemplate dependency property.

Constructors

BinaryRibbonSmartTextBox

public BinaryRibbonSmartTextBox()

Creates an empty smart text box, with the clear button turned on and no watermark.

Properties

AlertClueImageSource

public BitmapSource AlertClueImageSource

Gets or sets the flag picture shown once the box has text in it – the "all is well" state of a required field.

Value
The picture, drawn 12 x 12 device-independent units. The default is null.
Remarks

Shown only while IsAlertClueImageRenderingEnabled is true, from the first time text is typed.

See also

AlertClueImageSourceOnError

public BitmapSource AlertClueImageSourceOnError

Gets or sets the flag picture shown while the box is empty – the "needs attention" state of a required field.

Value
The picture, drawn 12 x 12 device-independent units. The default is null.
Remarks

It is shown from the moment the template is applied, whether or not IsAlertClueImageRenderingEnabled is set, and again whenever the box is emptied while that property is true.

See also

AlertFlagTooltipContent

public object AlertFlagTooltipContent

Gets or sets the tooltip shown over the flag picture – "Customer reference is required", say.

Value
Any tooltip content. The default is null, which shows no tooltip.
See also

ClearTextVisualContent

public object ClearTextVisualContent

Gets or sets what the clear button shows.

Value
Any content – text, or a small picture or path. The default is the text " X ", drawn bold.
Remarks

A click on the button empties the box. The button is drawn at the box's Control.FontSize.

ClearTextVisualForegroundBrush

public Brush ClearTextVisualForegroundBrush

Gets or sets the colour of the clear button's content while the button is disabled.

Value
The brush. The default is the ribbon skin's input text colour (BinaryRibbonThemeResources.InputForegroundBrushKey).
Remarks

The built-in template uses it only while the button is disabled, drawn faint. At other times the clear button takes the box's own Control.Foreground, and ClearTextVisualOnHoverForegroundBrush under the pointer.

ClearTextVisualOnHoverForegroundBrush

public Brush ClearTextVisualOnHoverForegroundBrush

Gets or sets the colour of the clear button's content while the pointer is over it.

Value
The brush. The default is red.
See also

ControlBorderBrush

public Brush ControlBorderBrush

Gets or sets the colour of the box's frame.

Value
The brush. The default is black.
Remarks

The built-in template draws the frame with this brush, not with Control.BorderBrush, so set this one to change it – to the skin's border colour, say, with ControlBorderBrush="{DynamicResource {x:Static ribbon:BinaryRibbonThemeResources.AllPurposeBorderBrushKey}}".

DataEntryMode

public DataEntryMode DataEntryMode

Gets or sets which characters the user can type into the box.

Value
The mode. The default is DataEntryMode.AlphaNumeric.
Remarks
ModeWhat can be typed

DataEntryMode.NumericOnly

The digits 0 to 9; anything else is refused.

DataEntryMode.AlphaNumeric

Anything. This mode does not filter, whatever its name suggests.

DataEntryMode.None

Anything except text that DisallowedInputRegularExpression matches; anything at all when that is not set.

The filter applies to characters as they are typed. Text pasted into the box, or set through TextBox.Text, is not checked.

Example
<!-- A quantity box that takes digits only. -->
<ribbon:BinaryRibbonSmartTextBox DataEntryMode="NumericOnly" WatermarkContent="Qty" Width="60" />

DisallowedInputRegularExpression

public string DisallowedInputRegularExpression

Gets or sets a regular expression for the characters the user may not type, when DataEntryMode is DataEntryMode.None.

Value
A .NET regular expression, matched against each piece of typed text. The default is null, which refuses nothing.
Remarks

Typed text that the expression matches anywhere is refused. The expression is used only in DataEntryMode.None mode; the other modes ignore it. An invalid expression throws an ArgumentException when the user next types.

Example
<!-- A file name box that refuses the characters Windows does not allow in file names. -->
<ribbon:BinaryRibbonSmartTextBox DataEntryMode="None"
                                 DisallowedInputRegularExpression="[\/:*?&quot;&lt;&gt;|]"
                                 WatermarkContent="Export file name" />

IsAlertClueImageRenderingEnabled

public bool IsAlertClueImageRenderingEnabled

Gets or sets whether the flag picture changes between AlertClueImageSourceOnError and AlertClueImageSource as the box is emptied and filled.

Value
true to switch the picture as the text changes. The default is false.
Remarks

Whatever its value, the flag shows AlertClueImageSourceOnError from the moment the template is applied, so a box with that picture set shows it even with this property off; it just never changes. Leave both pictures unset for no flag at all.

Example
<!-- A required field: a red flag until something is typed, then a green one. -->
<ribbon:BinaryRibbonSmartTextBox WatermarkContent="Customer reference"
                                 IsAlertClueImageRenderingEnabled="True"
                                 AlertClueImageSourceOnError="Images/FlagRed12.png"
                                 AlertClueImageSource="Images/FlagGreen12.png"
                                 AlertFlagTooltipContent="A customer reference is required" />

IsClearTextVisualAlwaysVisible

public bool IsClearTextVisualAlwaysVisible

Gets or sets whether the clear button is on show before anything has been typed.

Value
true to show the button from the start. The default is false.
Remarks

It decides only how the button starts out. As soon as the text changes, the button is shown while there is text and hidden while there is none, whatever this property says.

See also

IsClearTextVisualRenderingFeatureEnabled

public bool IsClearTextVisualRenderingFeatureEnabled

Gets or sets whether the clear button comes and goes with the text: shown while there is text, hidden while there is none.

Value
true to show the button whenever there is text. The default is true.
Remarks

With this and IsClearTextVisualAlwaysVisible both false, the box has no clear button.

WatermarkContent

public object WatermarkContent

Gets or sets the prompt shown in the box while it is empty and does not have the keyboard focus – "Search orders", "Customer name".

Value
Any content; usually a string. The default is null, which shows no prompt.
Remarks

The prompt is not part of TextBox.Text, and it ignores the pointer, so a click on it lands in the box.

The prompt is shown or hidden when the box gains or loses the keyboard focus and when the clear button is used, not on every change of text. Text set in code while the box does not have the focus leaves the prompt showing over it until the box next gains or loses the focus.

See also

WatermarkContentTemplate

public DataTemplate WatermarkContentTemplate

Gets or sets the template that draws WatermarkContent.

Value
The template. The default, from the control's style, draws the prompt in grey.
Example
<ribbon:BinaryRibbonSmartTextBox WatermarkContent="Search orders">
    <ribbon:BinaryRibbonSmartTextBox.WatermarkContentTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" FontStyle="Italic" Foreground="SlateGray" />
        </DataTemplate>
    </ribbon:BinaryRibbonSmartTextBox.WatermarkContentTemplate>
</ribbon:BinaryRibbonSmartTextBox>

Methods

OnApplyTemplate

public override void OnApplyTemplate()

Finds the parts of the new template – the clear button PART_ClearTextVisual, the flag PART_AlertClueImage, the text host PART_ContentHost and the watermark PART_WatermarkContent – and puts the watermark and flag in their starting state.

Fields

AlertClueImageSourceOnErrorProperty static

public static readonly DependencyProperty AlertClueImageSourceOnErrorProperty

Identifies the AlertClueImageSourceOnError dependency property.

AlertClueImageSourceProperty static

public static readonly DependencyProperty AlertClueImageSourceProperty

Identifies the AlertClueImageSource dependency property.

AlertFlagTooltipContentProperty static

public static readonly DependencyProperty AlertFlagTooltipContentProperty

Identifies the AlertFlagTooltipContent dependency property.

ClearTextVisualContentProperty static

public static readonly DependencyProperty ClearTextVisualContentProperty

Identifies the ClearTextVisualContent dependency property.

ClearTextVisualForegroundBrushProperty static

public static readonly DependencyProperty ClearTextVisualForegroundBrushProperty

Identifies the ClearTextVisualForegroundBrush dependency property.

ClearTextVisualOnHoverForegroundBrushProperty static

public static readonly DependencyProperty ClearTextVisualOnHoverForegroundBrushProperty

Identifies the ClearTextVisualOnHoverForegroundBrush dependency property.

ControlBorderBrushProperty static

public static readonly DependencyProperty ControlBorderBrushProperty

Identifies the ControlBorderBrush dependency property.

DataEntryModeProperty static

public static readonly DependencyProperty DataEntryModeProperty

Identifies the DataEntryMode dependency property.

DisallowedInputRegularExpressionProperty static

public static readonly DependencyProperty DisallowedInputRegularExpressionProperty

Identifies the DisallowedInputRegularExpression dependency property.

IsAlertClueImageRenderingEnabledProperty static

public static readonly DependencyProperty IsAlertClueImageRenderingEnabledProperty

Identifies the IsAlertClueImageRenderingEnabled dependency property.

IsClearTextVisualAlwaysVisibleProperty static

public static readonly DependencyProperty IsClearTextVisualAlwaysVisibleProperty

Identifies the IsClearTextVisualAlwaysVisible dependency property.

IsClearTextVisualRenderingFeatureEnabledProperty static

public static readonly DependencyProperty IsClearTextVisualRenderingFeatureEnabledProperty

Identifies the IsClearTextVisualRenderingFeatureEnabled dependency property.

WatermarkContentProperty static

public static readonly DependencyProperty WatermarkContentProperty

Identifies the WatermarkContent dependency property.

WatermarkContentTemplateProperty static

public static readonly DependencyProperty WatermarkContentTemplateProperty

Identifies the WatermarkContentTemplate dependency property.