Windows Phone 7 (WP7) Development and display of long text (height greater than 2000px)

Source: Internet
Author: User

During development, a piece of text is displayed. Naturally, I wrote a textblock, set it to highly automatic, and skillfully bound data ...... During the test, we found that the text section was too large and the textblock was not completely displayed. Baidu once found that many friends also encountered the same problem. It is estimated that Microsoft has restricted the display of this control considering the performance factors during the design.

Even worse, if the height of the outer control of the textblock is set to automatic, its height will change with the length of the text, assume that the outer layer of the textblock is a stackpanel. In this stackpanel, only the textblock has its height set to automatic. The text in the textblock is long, and the text height is set to PX. In this case, the textblock can only display PX, while stackpannel shows a blank 1000px ......

How can I solve this problem? I have found several ways to solve it:

1. Use a program to segment the text to be displayed, and then use ListBox to display multiple textblocks to display these text segments. The problem is that, because the font size is different, you cannot control whether the last line of each segment can be filled.

2,101 Windows Phone 7 apps, Volume I-developing apps 1-50The paginateddocument custom control is mentioned in chapter 25th. I have not read this carefully.

3. Yesterday I was thinking about using the embedded xNa to draw the text ...... Later I found out that it was too impractical. Because I wanted to display Chinese characters, I remember that xNa cached all the text into a texture before xna3.0 and showed Chinese characters, too much space is required. XNa 4.0, whether there are new changes, has not been made any time to study.

4. Use the webbrowser control to display the text on a webpage.

 

The first three "solutions" are abandoned due to known technical issues or relatively lazy issues ...... And the fourth solution seems feasible and simple.

(The intermediate attempt is not described in detail. Write the solution directly ).

Put a webbrowser control on the page and set the name to textviewer. To display text on it, you only need:

  

textViewer.NavigateToString("Hello world");

Test, no problem, "Hello world" is displayed. Success? Try "Hello World" for another Chinese character. Er, what you will see is garbled characters.

After checking the information, we found that webbrowser displays Unicode, so that the write can correctly display Chinese characters:

 

TEXT = "Hello World ";
String text_unicode;
VaR builder = new stringbuilder ();
Foreach (char C in text)
{
VaR B = (INT) C;
Builder. append ("& #" + B + ";");
}
Text_unicode = builder. tostring ();
Textviewer. navigatetostring (text_unicode );

This time we can correctly display Chinese characters.

 

In addition, Microsoft does not seem to recommend embedding webbrowser in pages, which may lead to poor user experience. I suggest that you first use textblock to display the abstract when you need to display long text. When you tap this abstract, a full-screen webbrowser will appear to display long text.

 

Please indicate the source for reprinting ~ Jin Yanyun

Http://www.cnblogs.com/vistach/archive/2012/02/17/Windows_Phone_WP7_TextBlock_long_text_webBrowser_2000px.html

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.