To align the text box within the layout of the page, use the HorizontalAlignment and VerticalAlignment properties. Use the TextAlignment property to align text within a text box. Here's what the text box looks like after text is added. ScrollViewer.SetVerticalScrollBarVisibility(textBox, ScrollBarVisibility.Auto) TextBox.TextWrapping = TextWrapping.Wrap You can show the vertical scrollbars by setting the ScrollViewer.VerticalScrollBarVisibility to Auto on the embedded ScrollViewer, as shown here. However, the vertical scrollbars are not visible by default. Scrolling using a scroll-wheel or touch is automatically enabled when needed. We recommend that you always specify an appropriate height for a multi-line text box, and not let it grow in height as the user types. You should test that a multi-line text box doesn't grow beyond its visible area, and constrain its growth if it does. If you try to use WrapWholeWords as a value for TextBox.TextWrapping or RichEditBox.TextWrapping an invalid argument exception is thrown.Ī multi-line text box will continue to grow vertically as text is entered unless it's constrained by its Height or MaxHeight property, or by a parent container. Note TextBox and RichEditBox don't support the WrapWholeWords value for their TextWrapping properties. This causes the text to wrap when it reaches the edge of the text box, independent of line separator characters. To enable text wrapping, set the TextWrapping property to Wrap.To let the text box allow and display the newline or return characters, set the AcceptsReturn property to true.You typically set both properties to make a multi-line text box. There are two properties that you can use to control whether the text box displays text on more than one line. If you need only to display text, consider using a TextBlock or RichTextBlock instead.Ī read-only text box looks the same as a read/write text box, so it might be confusing to a user. You can make the TextBox read-only until the conditions are met. For example, you might have a TextBox for a user to enter comments that is enabled only under certain conditions. You can make a TextBox read-only by setting the IsReadOnly property to true. If need text that is always read-only, consider using a TextBlock instead.
#TEXTBAR HTML CODE#
You typically toggle this property in your app code based on conditions in your app. You can make a text box read-only by setting the IsReadOnly property to true. The clear all button is not shown in any of these cases: The clear all button is shown only for editable, single-line text boxes that contain text and have focus. When a user clicks the "X", the text in the text box is cleared. The text box includes a clear all button ("X") that appears when text is entered in the box. Use the Paste event to modify pasted text if this is important for your app. However, MaxLength does not restrict the length of pasted text. You can restrict the number of characters the user can type by setting the MaxLength property. For design info, see Guidelines for labels. To customize the look of the header, you can set the HeaderTemplate property instead of Header. You can add a Header (or label) and PlaceholderText (or watermark) to the text box to give the user an indication of what the text box is for. SampleTextBox.Text = "Sample text retrieved"
#TEXTBAR HTML HOW TO#
This example shows how to get and set the current content of a text box. You typically use an event like a submit button click to access the Text property, but you can handle the TextChanged or TextChanging event if you need to do something when the text changes. It's common to use a text box to accept data input on a form, and use the Text property to get the complete text string from the text box. Here's the text box that results from this XAML. TextBox.PlaceholderText = "Type your notes here" Here's the XAML for a simple text box with a header and placeholder text.
#TEXTBAR HTML PASSWORD#
A password box looks like a text input box, except that it renders bullets in place of the text that has been entered. Use a PasswordBox control to collect a password or other private data, such as a Social Security number. If the text is never editable, consider using a TextBlock instead. You can make a TextBox read-only, but this should be a temporary, conditional state. You can use the Text property to get and set the text in a TextBox. Use a TextBox control to let a user enter and edit unformatted text, such as in a form. Platform APIs: TextBox class, Text property Is this the right control?