Skip to Main Content
Programming WPF, 2nd Edition
book

Programming WPF, 2nd Edition

by Chris Sells, Ian Griffiths
August 2007
Intermediate to advanced content levelIntermediate to advanced
864 pages
25h 52m
English
O'Reilly Media, Inc.
Content preview from Programming WPF, 2nd Edition

Text Controls

WPF provides controls for editing and displaying text. The simplest text editing control is TextBox. By default, it allows a single line of text to be edited, but by setting AcceptsReturn to true, it can edit multiple lines. It provides basic text editing facilities: selection support, system clipboard integration (cut, paste, etc.), and multilevel undo support.

Example 5-8 shows two TextBox elements, one with default settings and one in multiline mode.Figure 5-9 shows the results. (To illustrate the multiline text box, I typed "Enter" in the middle of the text before taking the screenshot.) Example 5-8 and Figure 5-9 also show PasswordBox, which is similar to TextBox, but is designed for entering passwords. As you can see, the text in the PasswordBox has been displayed as a line of identical symbols. This is common practice to prevent passwords from being visible to anyone who can see the screen. You can set the symbol with the PasswordChar property. The PasswordBox also opts out of the ability to copy its contents to the clipboard.

Example 5-8. TextBox and PasswordBox

<StackPanel Orientation="Horizontal">

  <TextBox Margin="5" VerticalAlignment="Center" Text="Single line textbox" />

  <TextBox AcceptsReturn="True" Margin="5" Height="50"
           VerticalScrollBarVisibility="Visible"
           VerticalAlignment="Center" Text="Multiline textbox" />

  <PasswordBox Margin="5" VerticalAlignment="Center" Password="Un5ecure" />

</StackPanel>

Figure 5-9. TextBox and PasswordBox

TextBox and PasswordBox ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, 4th Edition

Programming C#, 4th Edition

Jesse Liberty
Programming C# 10

Programming C# 10

Ian Griffiths

Publisher Resources

ISBN: 9780596510374Supplemental ContentErrata Page