BinaryRibbonSmartTextBox
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 | |
|---|---|
BinaryRibbonSmartTextBox | Creates an empty smart text box, with the clear button turned on and no watermark. |
| Properties | |
AlertClueImageSource | Gets or sets the flag picture shown once the box has text in it – the "all is well" state of a required field. |
AlertClueImageSourceOnError | Gets or sets the flag picture shown while the box is empty – the "needs attention" state of a required field. |
AlertFlagTooltipContent | Gets or sets the tooltip shown over the flag picture – "Customer reference is required", say. |
ClearTextVisualContent | Gets or sets what the clear button shows. |
ClearTextVisualForegroundBrush | Gets or sets the colour of the clear button's content while the button is disabled. |
ClearTextVisualOnHoverForegroundBrush | Gets or sets the colour of the clear button's content while the pointer is over it. |
ControlBorderBrush | Gets or sets the colour of the box's frame. |
DataEntryMode | Gets or sets which characters the user can type into the box. |
DisallowedInputRegularExpression | Gets or sets a regular expression for the characters the user may not type, when
DataEntryMode is DataEntryMode.None. |
IsAlertClueImageRenderingEnabled | Gets or sets whether the flag picture changes between AlertClueImageSourceOnError and
AlertClueImageSource as the box is emptied and filled. |
IsClearTextVisualAlwaysVisible | Gets or sets whether the clear button is on show before anything has been typed. |
IsClearTextVisualRenderingFeatureEnabled | Gets or sets whether the clear button comes and goes with the text: shown while there is text, hidden while there is none. |
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". |
WatermarkContentTemplate | Gets or sets the template that draws WatermarkContent. |
| Methods | |
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 | Identifies the AlertClueImageSourceOnError dependency property. |
AlertClueImageSourceProperty | Identifies the AlertClueImageSource dependency property. |
AlertFlagTooltipContentProperty | Identifies the AlertFlagTooltipContent dependency property. |
ClearTextVisualContentProperty | Identifies the ClearTextVisualContent dependency property. |
ClearTextVisualForegroundBrushProperty | Identifies the ClearTextVisualForegroundBrush dependency property. |
ClearTextVisualOnHoverForegroundBrushProperty | Identifies the ClearTextVisualOnHoverForegroundBrush dependency property. |
ControlBorderBrushProperty | Identifies the ControlBorderBrush dependency property. |
DataEntryModeProperty | Identifies the DataEntryMode dependency property. |
DisallowedInputRegularExpressionProperty | Identifies the DisallowedInputRegularExpression dependency property. |
IsAlertClueImageRenderingEnabledProperty | Identifies the IsAlertClueImageRenderingEnabled dependency property. |
IsClearTextVisualAlwaysVisibleProperty | Identifies the IsClearTextVisualAlwaysVisible dependency property. |
IsClearTextVisualRenderingFeatureEnabledProperty | Identifies the IsClearTextVisualRenderingFeatureEnabled dependency property. |
WatermarkContentProperty | Identifies the WatermarkContent dependency property. |
WatermarkContentTemplateProperty | Identifies the WatermarkContentTemplate dependency property. |
Constructors
BinaryRibbonSmartTextBox
Creates an empty smart text box, with the clear button turned on and no watermark.
Properties
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
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
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
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
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
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
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
Gets or sets which characters the user can type into the box.
- Value
- The mode. The default is
DataEntryMode.AlphaNumeric.
Remarks
| Mode | What can be typed |
|---|---|
The digits 0 to 9; anything else is refused. | |
Anything. This mode does not filter, whatever its name suggests. | |
Anything except text that
|
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
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="[\/:*?"<>|]"
WatermarkContent="Export file name" />IsAlertClueImageRenderingEnabled
Gets or sets whether the flag picture changes between AlertClueImageSourceOnError and
AlertClueImageSource as the box is emptied and filled.
- Value
trueto switch the picture as the text changes. The default isfalse.
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
Gets or sets whether the clear button is on show before anything has been typed.
- Value
trueto show the button from the start. The default isfalse.
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
Gets or sets whether the clear button comes and goes with the text: shown while there is text, hidden while there is none.
- Value
trueto show the button whenever there is text. The default istrue.
Remarks
With this and IsClearTextVisualAlwaysVisible both false, the box has
no clear button.
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
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
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
Identifies the AlertClueImageSourceOnError dependency property.
AlertClueImageSourceProperty static
Identifies the AlertClueImageSource dependency property.
AlertFlagTooltipContentProperty static
Identifies the AlertFlagTooltipContent dependency property.
ClearTextVisualContentProperty static
Identifies the ClearTextVisualContent dependency property.
ClearTextVisualForegroundBrushProperty static
Identifies the ClearTextVisualForegroundBrush dependency property.
ClearTextVisualOnHoverForegroundBrushProperty static
Identifies the ClearTextVisualOnHoverForegroundBrush dependency property.
ControlBorderBrushProperty static
Identifies the ControlBorderBrush dependency property.
DataEntryModeProperty static
Identifies the DataEntryMode dependency property.
DisallowedInputRegularExpressionProperty static
Identifies the DisallowedInputRegularExpression dependency property.
IsAlertClueImageRenderingEnabledProperty static
Identifies the IsAlertClueImageRenderingEnabled dependency property.
IsClearTextVisualAlwaysVisibleProperty static
Identifies the IsClearTextVisualAlwaysVisible dependency property.
IsClearTextVisualRenderingFeatureEnabledProperty static
Identifies the IsClearTextVisualRenderingFeatureEnabled dependency property.
WatermarkContentProperty static
Identifies the WatermarkContent dependency property.
WatermarkContentTemplateProperty static
Identifies the WatermarkContentTemplate dependency property.