Text Input Control in Windows Store Apps Using XAML

In this article we are going to learn about the TextBox control and how to add controls to your Windows Store apps built for Windows using C#.

The XAML framework for Windows Store apps is designed for Windows using XAML and includes several controls for entering and editing text, and a set of properties for formatting the text; those properties are:

  • TextBox: This type of control is used to enter plain text with limited text.
  • PasswordBox: PasswordBox is used for entering a Password from the user in the encypted form.
  • RichEditBox: It is used to enter or edit bulk text such as paragraphs.
In this article I will show how to embed these text controls in your Windows Store application using XAML.

TextBox


A TextBox control is used to enter and edit unformatted text. You can set the Text either using deisgn or through coding. Here's some important properties of the TextBox control:
  • Text: It sets or gets the text of the control.
  • IsReadOnly: It accepts a boolean value to make the textbox readonly or not.
  • TextWrapping: This property enables to wrap the text in the textbox.
  • Selected Text: It is used to get or set the selected text in the textbox.
  • Accept Return: This property makes the textbox multiline. It accepts a boolean value.
Here is an example of these properties and methods in use.

XAML code:

<TextBox x:Name="textBox1" Height="75" Width="300" Margin="10" Text="Some Text" TextWrapping="Wrap" AcceptsReturn="True"/>

       
Output

Textbox-Control-In-windows-Store-apps.jpg

PasswordBox

The PasswordBox control is used to enter a password into the textbox. The user cannot view the entered text. It only displays a dot for each character in the text. Here are some important properties of the PasswordBox:

  • Password: Gets or Sets the text in the PasswordBox.
  • PasswordChar: It specifies the password character. 
  • MaxLenth: It sets the maximum length that the user can enter.
Here's an example of the password box control.

XAML code
 

<PasswordBox x:Name="pwBox" Height="35" Width="200" MaxLength="8" />


Output

passwordbox-control-in-windows-store-apps.jpg
RichEditBox

The RichEditBox control is used to enter and edit bulk text as formatted text, like documents. Here is some important properties of the RichEditBox control:

  • Document: The Document property of the RichEditBox is for getting its content.
  • IsReadOnly: It accepts a boolean value to make the textbox readonly or not.
  • IsSpellCheckEnabled: It specifies whether to support spell checking.
Here's an example of the password box control.

XAML code
 

<RichEditBox x:Name="RichEdit" Width="200" Height="100" AcceptsReturn="True" TextWrapping="Wrap" HorizontalAlignment="Left"/>

Output

richeditbox-control-in-windows-store-apps.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all