Drawing text

Use a text control to display text in your application. This can include text that your user can modify, text that labels parts of your application, long passages of text with scrollbars, or text that is dynamically bound to data (see Bind an object to data).

Some controls are considered text controls because they display text (such as a button or check box). However, these other controls do not allow for rich-text editing. For this reason, Blend for Visual Studio 2012 includes a set of special text controls.

Special types of text controls

Text control

Supports rich text, shapes, and images

Editable at runtime

Available in Microsoft Silverlight projects

TextBox

343296b4-5c7d-4145-84cc-91b08ba67a1b

Provides an editable region that accepts text input. Use this control when you want users to be able to enter new text or edit existing text in your application. You can specify the font of the text at design time.

No

Yes

Yes

RichTextBox

0ee48635-456b-4ebd-b8e4-ce3658417b8e

Provides the same functionality as a TextBox object, but supports more text formatting properties and can contain any other type of object, such as an image or shape. Use this control when you want users to be able to enter rich text in multiple fonts with images and other objects. You can copy and paste content from most applications, including Microsoft Office Word and Internet Explorer.

Yes

Yes

Yes

TextBlock

42165963-00f7-4a33-abcd-b0849edebada

Provides a block of static text that the users of your application cannot edit. A TextBlock can contain any other type of object, such as an image or shape. Use this control when you must give instructions to your users, or to communicate information that doesn't require editing. Note that although text in this kind of control cannot be edited by users of your application, you can change the text through the code-behind file. You can copy and paste content from most applications, including Microsoft Office Word and Internet Explorer.

Yes

No

Yes

PasswordBox

31e4dc7e-8cf4-4014-83e4-9b50ec6ee663

Provides basic password functionality. Use this control to promote privacy in your application. When you do this, text that a user enters in the text control is masked by showing bullet point characters (6ece2a5b-0ada-496b-a403-4ccc8b5d463f), or another character that you specify in the PasswordChar property, instead of the characters that the user types.

No

Yes

Yes

Label

a27042f1-4067-4239-b99a-8b2e4c223de0

Provides a block of static content that you can use for basic labeling of other controls or user interface elements. A Label can contain text or content (such as an image or shape) but not both text and content at the same time. Additionally, this control provides mnemonic support, which offers functionality for keyboard accessibility and navigation through labeled controls that the user can access by pressing the Alt key in Windows-based applications.

No

No

Yes

FlowDocumentScrollViewer

16691128-7f3d-45e0-b532-45e8a7162416

Provides a block of static text with a scrollbar that the user can use to navigate through the text. It can also contain any other type of object, such as an image or shape. You can set properties for this control under Miscellaneous in the Properties panel to hide or show the vertical and horizontal scrollbars.

Yes

No

No

Working with text controls

Many aspects of working with text controls are the same as working with any other objects or controls in Blend. As with other objects, you can set the size and other layout properties of text control objects under Layout and Transform in the Properties panel. Likewise, you can set visual properties under Brushes and Appearance.

Certain attributes are unique to text control objects. You can modify these attributes in the following areas of the Properties panel, depending on the type of text control you are using:

  • Text   Change typographic properties such as font and paragraph alignment.

  • Brushes and Appearance   Change visual properties such as color and opacity.

  • Layout and Transform   Change size, layout, shape, and positioning.

  • CommonProperties and Miscellaneous   Change functional properties such as whether a text box includes a scroll bar.

Modifying the content of a text control

To modify the content of a text control at design time in Blend, select the control and press F2, or double-click the control on the artboard. When in this editing mode, you can set the properties in the preceding list, or type text directly into the control. You can also copy content from another source (such as a web page or Microsoft Word document) and paste it into the text control. If you copy rich text and other objects, the formatting and objects will be preserved if you are pasting into the RichTextBox, TextBlock, or FlowDocumentScrollViewer controls. Images can also be added to these text controls by dragging the image from in the Projects panel, or from outside Blend. For more information, see Edit text.

You can also set the content of a text control by binding the relevant property (for example, the Content property of a Button or the Text property of a TextBlock) to data. For more information, see Displaying data and Bind an object to data.

Making text editable in your application

You can control whether users of your Blend application can change the text that is contained in certain types of text controls (TextBox, RichTextBox, PasswordBox) in the application. For example, you can control whether users can enter new values or change existing values, or whether the text in your application is read-only. You can also disable text boxes in your application, so that functionality such as selection or scrolling is unavailable. By default, text boxes that you add to your application are editable and enabled. For more information, see Make text editable or read-only.

Formatting text

Options for formatting text in Blend appear under Text in the Properties panel. By setting these properties, you can control characteristics of the text in your application. These characteristics include font size and style, line height, paragraph spacing, text alignment, list style, and other typographic options. For more information, see Format text, Format paragraphs, Indent a line or a paragraph, or Create a bulleted or numbered list.

Note

If you want to animate formatting properties, then do not specify the properties when in text-editing mode (F2). Instead, press the ESC key to exit text-editing mode and then set the properties on the text object itself.

You can set additional properties to format your text under Common Properties in the Properties panel. These properties enable you to control text wrapping, to set whether the text is read-only or is editable by users of your application, and more. For more information, see Set text wrapping and Make text editable or read-only.

You can set the color of your text by setting properties under Brushes in the Properties panel. For more information, see Change the color of text objects.

Laying out text

You can use text controls in Blend in layout containers, just as you can any other object, and you draw them the same way. The text control shows more or less of its content depending on how you size the layout container. Additionally, RichTextBox, TextBlock, Label, and FlowDocumentScrollViewer text control objects themselves can contain other objects or controls.

When you put a text control in a layout container, you can anchor the edges of the text control to the edges of the container by using margins. When you set a margin and link alignment to that edge, the text control resizes to always keep that relationship intact. You can control the size of a text control even more by letting the text control expand or decrease either to the container (auto-size) or to the container with a minimum and maximum limit set, or by fixing the size of the control to absolute values.

Transforming text

You can transform text control objects in Blend just as you can any other vector object. Text in a text object remains editable even after you transform the object. Additionally, any changes that you or users of your application make to the content of a text control object, whether the changes are made during design time or during run time, will inherit the transformation that is applied to the parent control.

Font embedding

Blend contains functionality for embedding fonts in your project. Embedding makes sure that the font that you select for your application is the font that users will see when they run your application. Typically, users will already have most of the fonts that you can select in Blend, and therefore you do not have to embed them. If the user does not have your chosen font, a default system font will appear.

Important

If you do decide to embed, subset, or otherwise redistribute fonts in your application, it is your responsibility to make sure that you have the required license rights for those fonts.

For the fonts that come with Blend, see the Microsoft Software License Terms (EULA.language.rtf) file for full license terms. For other commercial fonts, see the Microsoft Typography website for information that can help you locate a particular font vendor or find a font vendor for custom work. To embed fonts in an Blend application, you can use the new Font Manager available in the Tools menu and available in the Advanced Properties section under Text in the Properties panel when you select a text control. For information about how to embed fonts in an Blend application, see Add a custom font to your application or Embed a font or a subset of a font in your application in this user guide, or see Packaging Fonts with Applications on MSDN.