Silverlight utility tip series: 55. Multiple line feed methods such as label, textblock, and textbox in Silverlight

Source: Internet
Author: User

In Silverlight, we often encounter line breaks when using labels, textblock, Textbox, and other controls. Here we use these three typical controls to look at the line breaks. In this article, we will divide the line feed into automatic line feed and manual line feed.

Automatic line feed

The label control does not support automatic line breaks in Silverlight.

Textblock and textbox can be automatically wrapped when the text exceeds the control width by setting the textwrapping = "Wrap" attribute.

Manual line feed

You can use the environment. newline attribute on the background to manually wrap labels, textblocks, and textbox controls.

Textblock can be stored in the XAMLCodeUse the <linebreak> label to manually wrap a line.

 

If you want to use the Enter key to wrap text in the textblock box, you need to set the acceptsreturn = "true" attribute.

First, let's look at the implementation of the automatic line feed XAML instance Code as follows:

 
<Border borderbrush = "blue" borderthickness = "1" width = "180" Height = "300"> <canvas> <textblock Height = "49" horizontalalignment = "Left" margin = ""42,111, 0, 0 "name =" textblock1 "text =" automatic line feed I will next line feed has been wrapped. "Verticalalignment =" TOP "textwrapping =" Wrap "width =" 120 "/> <textbox Height =" 60 "horizontalalignment =" Left "margin =" 42,192, 0, 0 "name =" textbox1 "verticalignment =" TOP "text =" automatically wrap the line. The next line has to be wrapped. "Textwrapping =" Wrap "acceptsreturn =" true "width =" 120 "/> </canvas> </Border>

Next, let's look at the code of the manual line feed XAML instance:

<Border borderbrush = "blue" margin = "300 0 50 50" borderthickness = "1" width = "180" Height = "300"> <canvas> <SDK: label Height = "45" horizontalalignment = "Left" margin = "42,10, 220 "name =" label2 "verticalignment =" TOP "width =" "/> <textblock Height =" 45 "horizontalalignment =" Left "margin =, 0, 0 "name =" textblock2 "text =" "verticalalignment =" TOP "width =" 178 "> <run> manually wrap your next line, </run> <linebreak/> <Ru N> line breaks. </Run> </textblock> <textblock Height = "45" horizontalalignment = "Left" margin = "42,110, 178 "verticalalignment =" TOP "name =" textblock3 "text =" "width =" "> </textblock> <textbox Height =" 45 "horizontalalignment =" Left "margin = ""42,160, 210 "name =" textbox2 "verticalignment =" TOP "acceptsreturn =" true "width =" "> </textbox> </canvas> </Border>

Finally, let's look at the implementation of the manual line feed XAML. CS Code as follows:

     Public   Partial   Class Mainpage: usercontrol
{
Public Mainpage ()
{
Initializecomponent ();
This . Label2.content = " Manually wrap your next line, " + Environment. newline + " Line feed. " ;
This . Textbox2.text = " Manually wrap your next line, " + Environment. newline + " Line feed. " ;
This . Textblock3.text = " Manually wrap your next line, " + Environment. newline + " Line feed. " ;
}
}

If you need the source code of this article, click sltest.zip to download it. The implementation result of this instance is as follows:

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.