SmartTextBox
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
SmartTextBox | Initializes a new instance of the SmartTextBox class. |
AlertClueImageSource | Gets or sets the alert clue image. |
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.) |
AlertFlagToolTipContent | Gets or sets the custom tooltip content for the alert flag visual. |
ClearTextVisualContent | Gets or sets the content for the clear data button located at the right hand side corner of the control. |
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. |
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. |
DataEntryMode | Gets or sets the data entry mode. |
DisallowedInputRegularExpression | Gets or sets the custom regular expression string to be used, when deciding what text input is not allowed. |
IsAlertClueImageRenderingEnabled | Gets or sets whether to render the alert clue image. |
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. |
IsClearTextVisualRenderingFeatureEnabled | Gets or sets a value indicating whether this instance is clear text visual rendering feature enabled. |
WatermarkContent | Gets or sets the watermark instance for the text box. |
WatermarkContentTemplate | Gets or sets the watermark template to use, for rendering the watermark instance. |
OnApplyTemplate | Is called when a control template is applied. |
AlertClueImageSourceOnErrorProperty | The alert clue image source on error property |
AlertClueImageSourceProperty | The alert clue image source property |
AlertFlagToolTipContentProperty | The alert flag tool tip content property |
ClearTextVisualContentProperty | The clear text visual content property |
ClearTextVisualForegroundProperty | The clear text visual foreground property |
ClearTextVisualOnHoverForegroundProperty | The clear text visual on hover foreground property |
DataEntryModeProperty | The data entry mode property |
DisallowedInputRegularExpressionProperty | The disallowed input regular expression property |
IsAlertClueImageRenderingEnabledProperty | The is alert clue image rendering enabled property |
IsClearTextVisualAlwaysVisibleProperty | The is clear text visual always visible property |
IsClearTextVisualRenderingFeatureEnabledProperty | The is clear text visual rendering feature enabled property |
WatermarkContentProperty | The watermark content property |
WatermarkContentTemplateProperty | The watermark content template property |
Constructors
SmartTextBox
Initializes a new instance of the SmartTextBox class.
Properties
AlertClueImageSource
Gets or sets the alert clue image.
Value. The alert clue image source.
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
Gets or sets the custom tooltip content for the alert flag visual.
Value. The content of the alert flag tool tip.
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
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
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
Gets or sets the data entry mode.
Value. The data entry mode.
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
Gets or sets whether to render the alert clue image.
Value. true if this instance is alert clue image rendering enabled; otherwise, false .
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
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
Gets or sets the watermark instance for the text box.
Value. The content of the watermark.
WatermarkContentTemplate
Gets or sets the watermark template to use, for rendering the watermark instance.
Value. The watermark content template.
Methods
OnApplyTemplate
Is called when a control template is applied.
Fields
AlertClueImageSourceOnErrorProperty
The alert clue image source on error property
AlertClueImageSourceProperty
The alert clue image source property
AlertFlagToolTipContentProperty
The alert flag tool tip content property
ClearTextVisualContentProperty
The clear text visual content property
ClearTextVisualForegroundProperty
The clear text visual foreground property
ClearTextVisualOnHoverForegroundProperty
The clear text visual on hover foreground property
DataEntryModeProperty
The data entry mode property
DisallowedInputRegularExpressionProperty
The disallowed input regular expression property
IsAlertClueImageRenderingEnabledProperty
The is alert clue image rendering enabled property
IsClearTextVisualAlwaysVisibleProperty
The is clear text visual always visible property
IsClearTextVisualRenderingFeatureEnabledProperty
The is clear text visual rendering feature enabled property
WatermarkContentProperty
The watermark content property
WatermarkContentTemplateProperty
The watermark content template property