Windows Phone development (10): commonly used controls (on) to: http://blog.csdn.net/tcjiaan/article/details/7295060

Source: Internet
Author: User
Tags silver light

Windows Phone controls come from several sources. Like traditional desktop application development or web development, controls are provided by default and those released by third-party openers. Generally, it is sufficient to use the default control if the interface layout is not too complex. In contrast, although many visual controls are provided in the android SDK, you will find that there are not many actually used controls, and many of them are completely decoration, no corresponding operation methods are made public, and no more listeners can be used by developers for processing themselves (here I am used to translating them into listeners, and there is no use of events like C # In Android, but a new listener. Of course, the principle is similar ).

In addition to game activation, we basically use Silverlight in WP. Therefore, most of the WP controls come from Silverlight (silver light ).

 

 

1. textblock control.

The function of this control is the same as that of textview in Android. Without it, it is used to display some static text. Of course, this static text does not mean that we cannot modify it, but is just a relative word, compared with the text box control that allows users to enter, there is nothing. If you have done winform development, it is equivalent to the label control. If you have been familiar with the development of MFC in VC ++, it is also similar to the static text control. Okay, it's a lot of nonsense. Let's take a look at the example.

 

[HTML]View plaincopyprint?

  1. <Textblock X: Name = "txtblock" text = "hello. "/>

 

Yes, so that we can declare a textblock in the page and set the text displayed above as "hello ".
I will not talk about how to declare controls. You can use the design view, drag and drop them from the toolbox, and set them in the "properties" window, which is similar to the traditional winform development.

For textblock controls, there may be two of the most common attributes:
1. Text. You don't need to introduce it much. Of course, it is the displayed text.
2. fontsize: Adjust the font size.

Next, let me take an example to illustrate the advanced usage of the textblock control? Ha, you will know after reading it.

[HTML]View plaincopyprint?

  1. <Textblock X: Name = "txtblock" fontsize = "42" textwrapping = "Wrap">
  2. Hello, <bold> Xiao Huang </bold>, <italic> what time do you get up today? </Italic>
  3. </Textblock>

(Figure 1)

In the above example, we can see that "hello" is normal, "yellow" is bold, and "When do you get up today" is italic. In other words, in textblock, we can use the relevant document format tag to enable
Format.

Let's look at another example.

[HTML]View plaincopyprint?

  1. <Textblock grid. Row = "2" fontsize = "40">
  2. Youku video <linebreak/> Tudou video
  3. </Textblock>

 

In this way, we can wrap the text.
(Figure 2)

Next let's take a look at the use of the run element. Because it is inherited from Silverlight, not all the tags are valid. Let's try more.

[HTML]View plaincopyprint?

  1. <Textblock grid. Row = "4" fontsize = "40" textwrapping = "Wrap">
  2. <Run fontstyle = "italic"
  3. Fontfamily = "tahoma"
  4. Fontsize = "65"
  5. Foreground = "orange">
  6. Moonlight in hetang
  7. </Run>
  8. </Textblock>

 

(Figure 3)

 

2. Button control.

I believe this guy doesn't need to introduce it. Everyone is most familiar with it. The frequency of Button development is very high, and it is also very simple to use, the key is to handle the click event, and it will basically be finished.

[HTML]View plaincopyprint?

  1. <Button content = "Click me" horizontalalignment = "Left" margin = "58,68," name = "button1" verticalignment = "TOP"
  2. Click = "button#click"/>

 

If you are not familiar with WPF or Silverlight,

(Figure 4)

 

We can see that the button is derived from contentcontrol, that is, if you want to set the text displayed on the button, you should set its content attribute.
Note that the content attribute is of the object type, that is, we can not only set text as the content of the button, as long as the displayed content can be assigned to the content attribute, do not believe it? Try it.

[HTML]View plaincopyprint?

  1. <Button horizontalalignment = "Left" margin = "58,68," name = "button1" verticalignment = "TOP"
  2. Click = "button#click">
  3. <Button. content>
  4. <Ellipse Height = "76" width = "125">
  5. <Ellipse. Fill>
  6. <Lineargradientbrush
  7. Startpoint = "0, 0"
  8. Endpoint = "1, 1">
  9. <Gradientstop color = "yellow" offset = "0.12"/>
  10. <Gradientstop color = "mediumvioletred" offset = "1"/>
  11. </Lineargradientbrush>
  12. </Ellipse. Fill>
  13. </Ellipse>
  14. </Button. content>
  15. </Button>

 

Check whether it is interesting after running it?
(Figure 5)

 

 

3. checkbox control.

Let alone this. Let's look at the example.

[HTML]View plaincopyprint?

  1. <Stackpanel orientation = "vertical">
  2. <Checkbox content = "cabbage" ischecked = "true"/>
  3. <Checkbox content = "Pears"/>
  4. <Checkbox content = "apple" ischecked = "false"/>
  5. <Checkbox content = "Flowers"/>
  6. </Stackpanel>

(Figure 6)

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.