[Wp8.1 (runtime)] Text block (textblock)

Source: Internet
Author: User
4.3 text block)

The textblock control is a lightweight control used to display a small amount of text. You can use textblock to display read-only text. You can understand textblock as a text display control. The control's XAML syntax is as follows:

<Textblock.../>

Or

<Textblock...> content </textblock>

Textblock is very common in Windows Phone applications. It is equivalent to a label that only serves to render text. Developers who have written HTML pages know that text can be directly written out of various HTML tags in HTML syntax, but in XAML syntax, text cannot be directly written outside the various controls of XAML. To do so, you must write the text to the textblock control to display it. The text content can be directly placed between the <textblock> and </textblock> labels, or can be assigned to the text attribute of textblock. Both syntaxes are equivalent. Next we will introduce some common features of the textblock control.

(1) Text attributes

Since the textblock control is a text display control, attributes related to the displayed text are often used in the control, suchFontfamilyAttribute(Font name, which can be set to Courier New, Times New Roman, verdana, and other fonts ),FontsizeAttribute(Text Size, in pixels, can be assigned to 1, 2, and other numbers ),FontstyleAttribute font style, which can be assigned to Arial, verdana, etc ),FontweightAttribute(The text width can be set to thin, extralight, light, normal, medium, semibold, bold, extrabold, black, and extrablack. Whether these values work depends on the selected font ). You can use these four text-related attributes to modify the appearance of textblock text information and combine them with a text UI effect that suits your application style.

(2) Implementation of text lines

In addition to text-related attributes, it is also very common for text folding. By default, the textblock control does not fold text strings. when the text is too long, it will cut off the text directly. Therefore, we need to implement the text line of the textblock control. The textblock control provides two ways to fold text. One is to set the textwrapping attribute to wrap or wrapwithoverflow, when the length of the text exceeds the width of the textblock control, it will be arranged in another row, so wrap and wrapwithoverflow will be slightly different, the difference is mainly for English words, if the length of a word is longer than the width of the textblock control, if it is set to the wrap value, the word is broken, if it is set to the wrapwithoverflow value, a complete word is not displayed in the line, there is no obvious difference between the two values in Chinese text. You can use the <linebreak/> label to fold rows. You can add the <linebreak/> label between the text and text lines to create another line.

(3) Split textblockControl text information

The text information of the textblock control is to divide the text information of a textblock control into multiple parts for display. For example, in a textblock control, you can set some strings to red, some of them are set to green. The implementation of this split depends on the inlines attribute of the textblock control. In the inlines attribute, you can use the run element label to separate the text content and set different style attributes, such as font and color, for the text information of different parts. The text information of the textblock control can be used to set different style effects for different texts in a text segment.

The following example shows how to set text block styles: how to define multiple styles, break lines, automatically fold lines of contents, and generate textblock controls in a textblock control.
Code list 4-2:Text block control demonstration (source code: Chapter 4th \ examples_4_2)

Mainpage. XAML file main code example <stackpanel X: Name = "stackpanel"> <! -Create a simple textblock control --> <textblock X: Name = "textblock2" fontsize = "20" Height = "30" text = "hello, I am a textblock control "foreground =" red "> </textblock> <! -Set different styles for the text content of the same textblock control --> <textblock fontsize = "20"> <textblock. inlines> <run fontweight = "bold" fontsize = "14" text = "textblock. "/> <run fontstyle =" italic "foreground =" red "text =" red text. "/> <run fontstyle =" italic "fontsize =" 18 "text =" linear gradient text. "> <run. foreground> <lineargradientbrush> <gradientstop color = "green" offset = "0.0"/> <gradientstop color = "Purple" offset = "0.25"/> <G Radientstop color = "orange" offset = "0.5"/> <gradientstop color = "blue" offset = "0.75"/> </lineargradientbrush> </run. foreground> </run> <run fontstyle = "italic" foreground = "green" text = "green"/> </textblock. inlines> </textblock> <! -Use linebreak to set the textblock control to fold rows --> <textblock fontsize = "20"> hello! <Linebreak/> I am textblock <linebreak/> goodbye <linebreak/> -- June 8, 2014 </textblock> <! -Set the textblock control to automatically fold rows --> <textblock textwrapping = "Wrap" fontsize = "30"> it seems that the content is too long; long </textblock> <! -Do not set the textblock control to automatically fold rows --> <textblock fontsize = "20"> it seems that the content is too long; long </textblock> <! -Set the color gradient of the textblock control content --> <textblock text = "color variations and variations" fontsize = "30"> <textblock. foreground> <lineargradientbrush> <gradientstop color = "# ff0000ff" offset = "0.0"/> <gradientstop color = "# ffeeeeee" offset = "1.0"/> </lineargradientbrush> </textblock. foreground> </textblock> </stackpanel>
Mainpage. xam. the main code of the CS file is unzip public mainpage () {This. initializecomponent (); // In. XAML. the CS page dynamically generates the textblock control textblock txtblock = new textblock (); txtblock. height = 50; txtblock. width = 200; txtblock. fontsize = 18; txtblock. TEXT = "textblock generated on the CS page"; txtblock. foreground = new solidcolorbrush (colors. blue); stackpanel. children. add (txtblock );}

This article comes from the introduction to Windows Phone 8.1 Application Development

Source code download: http://vdisk.weibo.com/s/zt_pyrfNHb99O

Welcome to my weibo @ WP Lin Zheng public account: Wp Development (No.: wpkaifa)

Wp8.1 technical exchange group: 372552293

 

[Wp8.1 (runtime)] Text block (textblock)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.