New Fashion Windows 8 Development (24): mysteries of text presentation

Source: Internet
Author: User
Textblock

This is the simplest text display control. How simple is it? Come on, you can also start vs to create a new project, while you can try it.

To display simple text in textblock, set the text attribute, for example:

<Textblock text = "Hello, have you had breakfast today? "/>

Run the command. Well, you can see the text.

At this time, I remembered that the font was too small to see clearly. What should I do? Can I modify the font size? Of course, see:

<Textblock text = "Hello, have you had breakfast today? "Fontsize =" 32 "/>

After modifying the fontsize, you will see a change in the font size. So, you will surely think, can it be bold? Let's take a look:

<Textblock text = "Hello, have you had breakfast today? "Fontsize =" 32 "fontweight =" bold "/>

Are there obvious changes?

 

At this time, you may have a new problem. In addition to displaying the characters we usually see, you can also display other characters. Of course, you can take a look at the following example:

Open the "character ing table" first. After using Windows for so many years, don't ask me how to open it.

Select segoe UI symbol as the font. Remember, do not select an error. In the symbol list, drag the scroll bar down and find the symbol you want. In the lower-left corner of the window, you can see the encoding.

Then, return to Vs and enter the following XAML:

<TextBlock Text="" FontSize="65" FontFamily="Segoe UI Symbol" />

The Code cannot be displayed. I just want.

Note the following when using these symbols:

1. The font must be segoe UI symbol;

2. Note the escape character. The input character must start with & # X, which is an XML/HTML Escape. For example, we can see in the character ing table that a character is encoded as U + e109, in XAML, replace it with & # xe109;

Clearly, there is a semicolon (;) next to it (;).

When you run the application, you will see the following results.

This kind of symbol is good. You don't need to draw the icon yourself in the future. You just need to use these symbols. Windows Vista will be able to use this font in the future.

If you don't write this escape, you can copy it. Where is it? Take a look at your "solution manager" and see the files marked in the figure below.

Haha, I will talk about it here. You will surely think about how to copy it. I believe that your understanding is very high.

 

As we can see the simple text displayed in textblock above, can it be more complicated? Yes.

For those who have a basic knowledge of WPF, I will mention that you will see the answer in the windows. UI. XAML. Documents namespace.

 

Can I wrap a line in textblock? Do you still remember the BR element in HTML? Haha, there are also in XAML. Do not believe it:

<Textblock fontsize = "32"> text in the first line <linebreak/> text in the second line <linebreak/> text in the third line </textblock>

Why? Run it on your own.

 

The following is another problem: can we achieve this effect? I show "we are good children .", I hope that the three words of the child will be shown in bold. The answer is yes. Come on.

<Textblock fontsize = "32"> we are all <bold> good kids </bold> </textblock>

This is a good result.

Let's take a look. I will show "happy programming, happy programming" in it. I want to highlight the word "programming" in green.

<Textblock fontsize = "32"> <span foreground = "lightgreen"> programming </span>: Happy <span foreground = "lightgreen"> programming </span>. </Textblock>

If you run the program, you will see the following results.

Let's take a closer look,

<Textblock fontsize = "32"> where do I come from <run fontsize = "50" fontweight = "black"> </run>, like a <italic fontsize = "45" foreground = "yellow"> dust </italic>. </Textblock>

What is the result?

Haha, how is this?

In fact, the difference between the run and span elements is not very big.

 

 

Richtextblock

Richtextblock is relatively powerful. Let's look at the example below.

<Richtextblock> <Paragraph> <span fontsize = "40" fontweight = "bold"> creation </span> LI <linebreak/> <run fontsize = "22"> author: zhang Ailing </run> </Paragraph> <Paragraph textindent = "36" fontsize = "20"> I have always been very kind to older people, people who are about to be older than they are a little bit concerned, and children are respectful and fearful. It's not because it's "awesome ". Most of them are ordinary after they grow up, and we may not be as good as our generation. </Paragraph> <Paragraph textindent = "36" fontsize = "20"> A child is a new force derived from the source of life, so it is respectable and commendable. </Paragraph> <Paragraph textindent = "36" fontsize = "20"> children are not as confused as we think. Most of the parents do not know their children, and their children often see through their parents. I remember how I was eager to reveal everything I knew when I was a child and scare elders. </Paragraph> <Paragraph textindent = "36" fontsize = "20" foreground = "# ffb4c3f9"> A young man is characterized by good forgetting, after the children's age, the children's psychology was completely forgotten until they were older and gradually approaching the children. The gap between them was a period, with the deepest vulgar disorder, completely lost contact with children-coincidentally, this is the time to have children. </Paragraph> <Paragraph textindent = "36" fontsize = "20"> animals are naturally loving and cruel, so one generation survived the fierce competition. "Nature" is mysterious and incredible, but we cannot "stop at nature ". The natural style is an amazing waste-a fish produces millions of fish and is swallowed up by other aquatics. A few of the remaining fish are lucky enough to hatch into small fish. Why are we wasting our blood? Civilized people are very valuable animals. Feeding and training requires a huge cost. We have limited energy and time to live. We can do so much and we have to do so much. Why should we create a large batch of waste that will be eliminated sooner or later? </Paragraph> <inlineuicontainer> 

Then run the application and you will see interesting results.

 

Richtextblock is similar to textblock, but it is richer. For example, in the above example, we can use inlineuicontainer to place our UI. In the above example, I put a hyperlinkbutton, you can put other elements as long as they are subclasses of uielement.

 

 

Richtextblockoverflow

If you observe carefully, both richtextblockoverflow and richtextblock have a common attribute-overflowcontenttarget. Its type is richtextblockoverflow. This is when the text is too long and richeditbox cannot be displayed, it will be placed in richtextblockoverflow, which is used in the previous article of this stuff, that is, the multi-column layout similar to the newspaper.

<Grid margin = "25"> <grid. columndefinitions> <columndefinition/> </grid. columndefinitions> <richtextblock margin = "15" grid. column = "0" overflowcontenttarget = "{binding elementname = of1}"> <Paragraph fontsize = "24" textindent = "46"> live in today's world, the peace of mind is not easy. The world is full of opportunities and pressure. Opportunity tempted people to try, pressure forced people to struggle, all make people calm down. I do not advocate that young people reject any opportunity, escape all pressure, and face the world with a closed attitude. The young mind should not have been sedated. The world belongs to young people. It is a necessary experience for life to take advantage of the young to the vast world. All we need to prevent is that we have completely given ourselves the opportunity and pressure to control, and lost our way home in the world. I used to walk around in a strange city. curiosity drove me to explore the busy streets and corners. On this way, you will inevitably get lost temporarily, but you must be confident that you can remember the route back to your place of residence. Otherwise, you will feel uneasy. I think so is life. You may wish to make a fortune in the world, start a job, explore adventure, and seek for love. However, you must not forget your way home. This is your self, your own spiritual world. To seek peace of mind, you must first have a mind. In theory, everyone has a mind, but in fact they are not. There are some people who are always influenced by the external power and live in the noisy external world without having a real inner life. For such a person, there is no way to talk about the peace of mind. Only by paying attention to the soul can a person be disturbed by the soul and seek peace of mind. Therefore, it is the most important thing to have the endowment of your life or to develop such a habit. People with this endowment or habit know that inner life and external life are not mutually exclusive. The same person may be very rich in both aspects. The difference is that people who focus on their inner lives are good at turning the harvest of external life into the wealth of the soul. Those who lack such endowment or habits will often be lost in external life, people are scattered. Self is a central point. A person has a solid self, and he has spiritual coordinates in this world. he can find his way home no matter how far he goes. For another example, we may say that a person with a solid self may seem to have a mental close friend who carries this friend wherever he goes, this close friend will faithfully share all his experiences and listen to all his words. If a person has his or her own spiritual pursuits and experiences in the world, then he will gradually recognize his position in the world. The world is infinite and the temptation is endless. However, the practical possibilities of everyone are limited. You may wish to maintain an open mind for all possibilities, because it is the source of life charm, but at the same time, you must leave your own anchor on the sea of the world, find the most suitable domain. No matter how great or ordinary a person is, as long as he adapts to his nature, finds what he really likes to do, and does what he likes to do perfectly, he has an unbreakable home in this world. As a result, he will not only have enough courage to bear the pressure of the outside world, but also be awake enough to face the temptation of various opportunities. Of course we have no reason to doubt that such a person will be able to reap the enrichment of life and the peace of mind. </Paragraph> </richtextblock> <richtextblockoverflow X: Name = "of1" grid. column = "1" margin = "15" overflowcontenttarget = "{binding elementname = of2}"/> <richtextblockoverflow X: Name = "of2" grid. column = "2" margin = "15"/> </GRID>

Looking at the above XAML, richtextblock is placed in the first column of the grid that is evenly divided into three columns. However, because the space in the first column cannot display all text, the overflowcontenttarget attribute is set to richtextblockoverflow in the second column, the richtextblockoverflow in the second column is used up, and the text is too long to be displayed. At this time, the overflowcontenttarget of richtextblockoverflow points to the richtextblockoverflow in the third column.

This is why both richtextblock and richtextblockoverflow have an overflowcontenttarget attribute. If you want to determine whether the text overflows in the code, you can access the hasoverflowcontent attribute. If it is true, text overflow exists, it is not until the hasoverflowcontent of a richtextblockoverflow is false that no overflow text exists.

Shows the running result of this example.

 

 

 

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.