Namespace
Inheritance
Control → TemplatedControl → TextBox
Properties
Gets or sets the text content of the TextBox. Supports two-way binding.
Gets or sets whether the TextBox allows and displays newline or return characters (multi-line mode).
Gets or sets whether the TextBox allows and displays tabs.
Gets or sets whether this TextBox is read-only.
Gets or sets the character that should be used for password masking.
Gets or sets the index of the text caret.
Gets or sets the starting position of the text selected in the TextBox.
Gets or sets the end position of the text selected in the TextBox.
Gets or sets the text selected in the TextBox.
Gets or sets the maximum number of characters that the TextBox can accept. This constraint only applies for manually entered (user-inputted) text.
Gets or sets the maximum number of visible lines to size to.
Gets or sets the minimum number of visible lines to size to.
Gets or sets the text alignment. Values:
Left, Center, Right, Justify.Gets or sets the text wrapping mode. Values:
NoWrap, Wrap, WrapWithOverflow.Gets or sets the placeholder or descriptive text that is displayed even if the Text property is not yet set.
Gets or sets the brush used for the foreground color of the placeholder text.
Gets or sets whether the PlaceholderText will still be shown above the Text even after a text value is set.
Gets or sets a brush that is used to highlight selected text.
Gets or sets a brush that is used for the foreground of selected text.
Gets or sets a brush that is used for the text caret.
Gets or sets whether undo/redo is enabled. Default is
true.Gets or sets the maximum number of items that can reside in the Undo stack.
Gets whether the Cut command can be executed. Read-only.
Gets whether the Copy command can be executed. Read-only.
Gets whether the Paste command can be executed. Read-only.
Gets whether the undo stack has an action that can be undone. Read-only.
Gets whether the redo stack has an action that can be redone. Read-only.
Events
Occurs asynchronously after text changes and the new text is rendered.
Occurs synchronously when text starts to change but before it is rendered. This event occurs just after the Text property value has been updated.
Raised when content is being copied to the clipboard.
Raised when content is being cut to the clipboard.
Raised when content is being pasted from the clipboard.
Methods
Cuts the current text onto the clipboard.
Copies the current text onto the clipboard.
Pastes the current clipboard text content into the TextBox.
Clears the current selection, maintaining the CaretIndex.
Selects all text in the TextBox.
Gets the number of lines in the TextBox, or -1 if no layout information is available.
Template Parts
The text presenter that displays the text. Required.
Optional scroll viewer for scrolling text content.
Usage
XAML Example - Basic TextBox
XAML Example - Multi-line TextBox
XAML Example - Password TextBox
XAML Example - Read-Only TextBox
C# Example - Text Binding
C# Example - Selection
Clipboard Operations
Validation Example
Source File
TextBox.cs:1-1400+
See Also
- TextBlock - Read-only text display
- AutoCompleteBox - TextBox with suggestions
- MaskedTextBox - TextBox with input masking