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
Download informationTo download this code sample, click the following link:
Technical overviewTo 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.
- 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:Or, set FontFamily at code behind, as it is set in the sample:
<TextBlock 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.
paragraph1.FontFamily = new FontFamily("Magnetob.ttf#Magneto");
- 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.
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.
LanguagesThis code sample contains the following programming languages.
|Visual Basic .NET||VBSL3Text|
- Microsoft® Silverlight™ 3 Tools for Visual Studio 2008 SP1
- Silverilght 3 runtime
- This sample application was created by using Visual Studio 2008 with Service Pack 1 installed.
- Text, Silverlight
What is All-In-One Code Framework?All-In-One Code Framework uses code samples in different programming languages to illustrate most Microsoft development techniques. Each code sample is carefully selected, composed, and documented to show common code scenarios. For more information about All-In-One Code Framework, visit the following All-In-One Code Framework Web site:
How to find more All-In-One Code Framework samplesTo find more All-In-One Code Framework samples, search for "kbcodefx" together with related keywords on the Microsoft support Web site. Or, visit the following Microsoft Web site:
Rapid publishing disclaimerMicrosoft corporation and/or its respective suppliers make no representations about the suitability, reliability, or accuracy of the information and related graphics contained herein. All such information and related graphics are provided "as is" without warranty of any kind. Microsoft and/or its respective suppliers hereby disclaim all warranties and conditions with regard to this information and related graphics, including all implied warranties and conditions of merchantability, fitness for a particular purpose, workmanlike effort, title and non-infringement. You specifically agree that in no event shall Microsoft and/or its suppliers be liable for any direct, indirect, punitive, incidental, special, consequential damages or any damages whatsoever including, without limitation, damages for loss of use, data or profits, arising out of or in any way connected with the use of or inability to use the information and related graphics contained herein, whether based on contract, tort, negligence, strict liability or otherwise, even if Microsoft or any of its suppliers has been advised of the possibility of damages.
Article ID: 981904 - Last Review: 12/12/2015 03:59:19 - Revision: 1.1
- kbnosurvey kbarchive kbexpertiseadvanced kbsurveynew kbinfo kbnomt kbrapidpub kbcodefx atdownload KB981904