HypernovaDesktop Components · docs
Binarymission
WPF › Smart Text Box › SmartTextBox

SmartTextBox

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

A custom text box control that is capable of rendering Watermark with image and text.

public class SmartTextBox : TextBox

Inherits from / implements: TextBox

Remarks

How this control works. A TextBox whose template adds a watermark, a clear-text button and an alert image, and which filters what can be entered according to DataEntryMode. The text itself is the base class's; this control only decides when each extra visual shows and which input is refused. Three visuals, one rule each. The template gives this control a watermark presenter, a clear-text button and an alert image, and the control decides when each is shown. Every one of those decisions is made in a single Refresh method, called from the template, from TextChanged and from the property callbacks - because each visual's state depends on more than one property, and a rule written out at each of the places that can change it is a rule that will disagree with itself. Why the template's bindings cannot be relied on. The template binds the clear button's Visibility and the alert image's Source . The moment the control writes either of those in code it sets a local value, which outranks a template binding permanently - the binding never applies again for the life of the control. So the code owns both from the first refresh onward and has to account for every property the template binding would otherwise have covered. The input filter runs in two places. DataEntryMode is enforced on PreviewTextInput , which sees typing, and on the pasting handler, which sees Ctrl+V and the context menu - a filter on typing alone is no filter at all, since the text it refuses can be pasted in whole. Both ask IsDisallowed , so they cannot disagree. Text dropped on the control is not filtered; a caller that needs that turns AllowDrop off. Numeric means ASCII digits. The filter tests the 0 to 9 range rather than IsDigit(char), which is true of digits in a dozen other scripts that no invariant-culture parse will accept afterwards.

Members at a glance

SmartTextBoxInitializes a new instance of the SmartTextBox class.
AlertClueImageSourceGets or sets the alert clue image.
AlertClueImageSourceOnErrorGets or sets the image that will be rendered when the control is in error mode (i.e. you could use this when the user has not set a mandatory data in teh control, etc.)
AlertFlagToolTipContentGets or sets the custom tooltip content for the alert flag visual.
ClearTextVisualContentGets or sets the content for the clear data button located at the right hand side corner of the control.
ClearTextVisualForegroundGets or sets the foreground brush for the clear text command visual that is rendered at the right hand side corner of the control.
ClearTextVisualOnHoverForegroundGets or sets the foreground brush for the clear text command visual that is rendered at the right hand side corner of the control, when mouse hovers on it.
DataEntryModeGets or sets the data entry mode.
DisallowedInputRegularExpressionGets or sets the custom regular expression string to be used, when deciding what text input is not allowed.
IsAlertClueImageRenderingEnabledGets or sets whether to render the alert clue image.
IsClearTextVisualAlwaysVisibleGets or sets whether the clear text visual is always shown in the control, irrespective of whether the user has any text typed into the control or not.
IsClearTextVisualRenderingFeatureEnabledGets or sets a value indicating whether this instance is clear text visual rendering feature enabled.
WatermarkContentGets or sets the watermark instance for the text box.
WatermarkContentTemplateGets or sets the watermark template to use, for rendering the watermark instance.
OnApplyTemplateIs called when a control template is applied.
AlertClueImageSourceOnErrorPropertyThe alert clue image source on error property
AlertClueImageSourcePropertyThe alert clue image source property
AlertFlagToolTipContentPropertyThe alert flag tool tip content property
ClearTextVisualContentPropertyThe clear text visual content property
ClearTextVisualForegroundPropertyThe clear text visual foreground property
ClearTextVisualOnHoverForegroundPropertyThe clear text visual on hover foreground property
DataEntryModePropertyThe data entry mode property
DisallowedInputRegularExpressionPropertyThe disallowed input regular expression property
IsAlertClueImageRenderingEnabledPropertyThe is alert clue image rendering enabled property
IsClearTextVisualAlwaysVisiblePropertyThe is clear text visual always visible property
IsClearTextVisualRenderingFeatureEnabledPropertyThe is clear text visual rendering feature enabled property
WatermarkContentPropertyThe watermark content property
WatermarkContentTemplatePropertyThe watermark content template property

Constructors

SmartTextBox

public SmartTextBox()

Initializes a new instance of the SmartTextBox class.

Properties

AlertClueImageSource

public BitmapSource AlertClueImageSource

Gets or sets the alert clue image.

Value. The alert clue image source.

AlertClueImageSourceOnError

public BitmapSource AlertClueImageSourceOnError

Gets or sets the image that will be rendered when the control is in error mode (i.e. you could use this when the user has not set a mandatory data in teh control, etc.)

Value. The alert clue image source on error.

AlertFlagToolTipContent

public object AlertFlagToolTipContent

Gets or sets the custom tooltip content for the alert flag visual.

Value. The content of the alert flag tool tip.

ClearTextVisualContent

public object ClearTextVisualContent

Gets or sets the content for the clear data button located at the right hand side corner of the control.

Value. The content of the clear text visual.

ClearTextVisualForeground

public Brush ClearTextVisualForeground

Gets or sets the foreground brush for the clear text command visual that is rendered at the right hand side corner of the control.

Value. The clear text visual foreground.

ClearTextVisualOnHoverForeground

public Brush ClearTextVisualOnHoverForeground

Gets or sets the foreground brush for the clear text command visual that is rendered at the right hand side corner of the control, when mouse hovers on it.

Value. The clear text visual on hover foreground.

DataEntryMode

public SmartTextBoxDataEntryMode DataEntryMode

Gets or sets the data entry mode.

Value. The data entry mode.

DisallowedInputRegularExpression

public string DisallowedInputRegularExpression

Gets or sets the custom regular expression string to be used, when deciding what text input is not allowed.

Value. The disallowed input regular expression.

IsAlertClueImageRenderingEnabled

public bool IsAlertClueImageRenderingEnabled

Gets or sets whether to render the alert clue image.

Value. true if this instance is alert clue image rendering enabled; otherwise, false .

IsClearTextVisualAlwaysVisible

public bool IsClearTextVisualAlwaysVisible

Gets or sets whether the clear text visual is always shown in the control, irrespective of whether the user has any text typed into the control or not.

Value. true if this instance is clear text visual always visible; otherwise, false .

IsClearTextVisualRenderingFeatureEnabled

public bool IsClearTextVisualRenderingFeatureEnabled

Gets or sets a value indicating whether this instance is clear text visual rendering feature enabled.

Value. true if this instance is clear text visual rendering feature enabled; otherwise, false .

WatermarkContent

public object WatermarkContent

Gets or sets the watermark instance for the text box.

Value. The content of the watermark.

WatermarkContentTemplate

public DataTemplate WatermarkContentTemplate

Gets or sets the watermark template to use, for rendering the watermark instance.

Value. The watermark content template.

Methods

OnApplyTemplate

public override void OnApplyTemplate()

Is called when a control template is applied.

Fields

AlertClueImageSourceOnErrorProperty

public static readonly DependencyProperty AlertClueImageSourceOnErrorProperty

The alert clue image source on error property

AlertClueImageSourceProperty

public static readonly DependencyProperty AlertClueImageSourceProperty

The alert clue image source property

AlertFlagToolTipContentProperty

public static readonly DependencyProperty AlertFlagToolTipContentProperty

The alert flag tool tip content property

ClearTextVisualContentProperty

public static readonly DependencyProperty ClearTextVisualContentProperty

The clear text visual content property

ClearTextVisualForegroundProperty

public static readonly DependencyProperty ClearTextVisualForegroundProperty

The clear text visual foreground property

ClearTextVisualOnHoverForegroundProperty

public static readonly DependencyProperty ClearTextVisualOnHoverForegroundProperty

The clear text visual on hover foreground property

The default is frozen. A dependency property's default is one object shared by every instance in the process, so an unfrozen brush here is a brush any caller can reach and recolour for every text box in the application at once.

DataEntryModeProperty

public static readonly DependencyProperty DataEntryModeProperty

The data entry mode property

DisallowedInputRegularExpressionProperty

public static readonly DependencyProperty DisallowedInputRegularExpressionProperty

The disallowed input regular expression property

IsAlertClueImageRenderingEnabledProperty

public static readonly DependencyProperty IsAlertClueImageRenderingEnabledProperty

The is alert clue image rendering enabled property

IsClearTextVisualAlwaysVisibleProperty

public static readonly DependencyProperty IsClearTextVisualAlwaysVisibleProperty

The is clear text visual always visible property

IsClearTextVisualRenderingFeatureEnabledProperty

public static readonly DependencyProperty IsClearTextVisualRenderingFeatureEnabledProperty

The is clear text visual rendering feature enabled property

WatermarkContentProperty

public static readonly DependencyProperty WatermarkContentProperty

The watermark content property

WatermarkContentTemplateProperty

public static readonly DependencyProperty WatermarkContentTemplateProperty

The watermark content template property