Partilhar via


Text and typography overview

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 data to a property or element).

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, Microsoft Expression Blend 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 1.0 projects

Available in Microsoft Silverlight 2 projects

TextBox

Cc295153.343296b4-5c7d-4145-84cc-91b08ba67a1b(en-us,Expression.10).png

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

No

Yes

RichTextBox

Cc295153.0ee48635-456b-4ebd-b8e4-ce3658417b8e(en-us,Expression.10).png

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

No

No

TextBlock

Cc295153.42165963-00f7-4a33-abcd-b0849edebada(en-us,Expression.10).png

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

Yes

PasswordBox

Cc295153.31e4dc7e-8cf4-4014-83e4-9b50ec6ee663(en-us,Expression.10).png

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 (Cc295153.6ece2a5b-0ada-496b-a403-4ccc8b5d463f(en-us,Expression.10).png), or another character that you specify in the PasswordChar property, instead of the characters that the user types.

No

Yes

No

Yes

Label

Cc295153.a27042f1-4067-4239-b99a-8b2e4c223de0(en-us,Expression.10).png

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

No

No

FlowDocumentScrollViewer

Cc295153.16691128-7f3d-45e0-b532-45e8a7162416(en-us,Expression.10).png

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

No

Cc295153.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

Working with text controls

Many aspects of working with text controls are the same as working with any other objects or controls in Expression 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.

Cc295153.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

Modifying the content of a text control

To modify the content of a text control at design time in Expression 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 under Files in the Projects panel, or from outside Expression 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 Data handling overview and Bind data to a property or element.

Cc295153.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

Making text editable in your application

You can control whether users of your Expression 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.

Cc295153.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

Formatting text

Options for formatting text in Expression 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.

Cc295153.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

Laying out text

You can use text controls in Expression 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.

Note

Only the Canvas layout container is available in a Silverlight 1.0 project.

Cc295153.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

Transforming text

You can transform text control objects in Expression 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.

Cc295153.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top

Font embedding

Expression Blend 2 contains new 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 Expression 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 Expression 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 Expression 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 Expression 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.

Note

Font embedding is not available in a Silverlight 1.0 project.

Cc295153.7e183f1f-37d8-4dcb-980c-19a5d61ca087(en-us,Expression.10).gifBack to top