Windows phone (19) learn more about TextBlock

Source: Internet
Author: User

 TextBlock

It is generally used to display Text elements. We usually use the Text attribute of this class. In fact, there are two ways to display Text. One is to set the internal Text, the other is to create a new Run object and LineBreak object in the Inlines set, which is called inline text]

The content of the Run label is the value of the Text attribute, which has some attributes of the TextBlock class, such as FontFamily, FontSize, FontStretch, and Foregroud;

New Line of LineBreak, line feed label

<Grid x: Name = "ContentPanel" Grid. Row = "1" Margin = "12,0, 12,0">
<TextBlock x: Name = "tbShow" Text = "Text Example" Foreground = "White" verticalignment = "Center" HorizontalAlignment = "Center">
<TextBlock. Inlines>
<Run Foreground = "Blue" Text = "ddd"> </Run>
</TextBlock. Inlines>
</TextBlock>
</Grid>

We can see the foreground and displayed text set in both the Run tag and the TextBlock tag, but what is the effect:

 

So we are sure that if the properties of the TextBlock label and the Run label defined in the TextBlock label are the same, the properties of the two are irrelevant, but the displayed Text set by Run is after the TextBlock attribute Text, if you want to run the program, the designer will directly see this error,

 

 

Let's take a look at the example below. We have listed some properties of the Run tag:

<! -- ContentPanel-place other content here -->
<Grid x: Name = "ContentPanel" Grid. Row = "1" Margin = "12,0, 12,0">
<TextBlock x: Name = "tbShow" Text = "Text Example" Foreground = "White" verticalignment = "Center" HorizontalAlignment = "Center">
<Run Foreground = "Blue"> Foreground Blue </Run> <LineBreak> </LineBreak>
<Run FontStyle = "Italic"> font style Italic </Run> <LineBreak> </LineBreak>
<Run FontSize = "30"> font 30 </Run> <LineBreak> </LineBreak>
<Run TextDecorations = "Underline"> Underline </Run> <LineBreak> </LineBreak>
<Run TextDecorations = "Underline"
FontSize = "30"
FontStyle = "Italic"
Foreground = "Blue"
Text = "Comprehensive"> </Run> <LineBreak> </LineBreak>
</TextBlock>
</Grid>

The result is as follows:

 

This section describes the inline Text of the Inlines set. This is a special usage of the TextBlock attribute Text.

 

Case code:

<! -- ContentPanel-place other content here -->
<Grid x: Name = "ContentPanel" Grid. Row = "1" Margin = "12,0, 12,0">
<TextBlock x: Name = "tbShow" Foreground = "White"
VerticalAlignment = "Center" HorizontalAlignment = "Center"
Text = "π indicates 3.14"
>
</TextBlock>
</Grid>

It achieves the following effects:

 

For example. End (.),
Enter,
Line feed. You can see that the format is similar. You can change the last letter or number to see what it is, for example

〇 is a circle. When using line breaks, we can set the TextBlock attribute TextWrapping = "Wrap", which indicates that when the display text exceeds the width limited by the container, text is automatically wrapped;

You can also set the text alignment mode. The TextAlignment attribute can be left, right, or center;

If you set the fontfamily attribute in textblock and the name is incorrect, the system will use the default font, however, if the font is obtained from a hidden file, the error font is still obtained;

MediaElement

 

 

It indicates the playing media. Currently, mp4, wma, mp3, and wmv are supported (ps: I just found a swf format not supported by Youku). The default AutoPlay attribute of MediaElement is True, therefore, when the video is buffered and can be played, the video will be automatically played.

The reference address sets the playback source. The xaml code is as follows:

<! -- ContentPanel-place other content here -->
<Grid x: Name = "ContentPanel" Background = "AntiqueWhite" Grid. Row = "1" Margin = "12,0, 12,0">

<MediaElement Source = "http://www.charlespetzold.com/Media/Walrus.wmv"> </MediaElement>
</Grid>

During playback:

 

This is Charles Petzold, no matter how grateful he brings us knowledge, can also visit his own website http://www.charlespetzold.com/

 

Related Article

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.