Search Wiki:
Resource Page Description
Text plays a critical role in many applications. Microsoft Silverlight 3 provides extensive support for working with texts. This article describes an All-In-One Code Framework sample that is available for downloading. This sample includes a step-by-step guide about how to work with text in Silverlight 3.

This article covers the following functionalities:
Create a simple TextBlock
Create a TextBlock with multiple Runs and LineBreaks
Create a TextBlock with advanced format
Select all text in a TextBox using code




INTRODUCTION

Text plays a critical role in many applications. Microsoft Silverlight 3 provides extensive support for working with texts. This article describes an All-In-One Code Framework sample that is available for downloading. This sample includes a step-by-step guide about how to work with text in Silverlight 3.

This article covers the following functionalities:
Create a simple TextBlock
Create a TextBlock with multiple Runs and LineBreaks
Create a TextBlock with advanced format
Select all text in a TextBox using code

Difficulty level

codefx_Beginner.jpg

Download information

Please visit http://support.microsoft.com/kb/981904 to download the code samples.

Technical overview


To customize the way text is displayed in Silverlight, you can use various methods. For example, to use custom font, you can use one of the following methods.

Method 1
Include the custom font file in the Silverlight project.

Note In this sample, the custom font file is Magnetob.ttf.
Select the custom font file in the Solution Explorer window of Microsoft Visual Studio.
In the Properties window, set Build Action to Resource.
Set FontFamily in XAML by using the following syntax:
<TextBlock FontFamily="Magnetob.ttf#Magneto"…

Or, set FontFamily at code behind, as it is set in the sample:
paragraph1.FontFamily = new FontFamily("Magnetob.ttf#Magneto");

Note In this sample code, Magnetob.ttf is the font file name. The file name is case insensitive. Additionally, because one font file may contain multiple fonts, you must specify the fonts that you want to use. In this sample code, the Magneto font was specified.
Method 2
In Expression Blend, click the Font Manager button that is on the Text tab in the Properties panel.
Select the font(s) that you want to embed in the Silverlight application.
Select your text control, and then choose the desired font for the text control.
Font management is just one of the text features that are supported by Silverlight 3. For more information about how to work with text in Silverlight 3, run the sample project. The sample itself is an interactive document.

Note For more information about how to create and then deploy the sample application, refer to the Readme.txt file that is included in the download package.

Technology category

Silverlight

Languages

Language Project Name
Visual C# CSSL3Text
Visual Basic .NET VBSL3Text
XAML XAMLSL3Text

Prerequisites

*Silverilght 3 runtime http://www.silverlight.net/getstarted
*This sample application was created by using Visual Studio 2008 with Service Pack 1 installed.

MORE INFORMATION


What is All-In-One Code Framework?
All-In-One Code Framework shows most Microsoft development techniques by using code samples in different programming languages. Each example is carefully selected, composed, and documented to show one common code scenario. For more information about All-In-One Code Framework, visit the following Web site: http://1code.codeplex.com

How to find more All-In-One Code Framework samples
To find more All-In-One Code Framework samples, you can search for kbcodefx together with related keywords on support.microsoft.com. Or, you can simply click the following link: http://support.microsoft.com/search/default.aspx?query=kbcodefx

REFERENCES


For more information, visit the following Web sites:

MSDN: TextBox http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox(VS.95).aspx
MSDN: TextBlock class http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock(VS.95).aspx
Last edited Apr 6 2010 at 2:57 AM  by pqokb, version 2
Updating...
Page view tracker