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.
<TextBlock x: Name = "txtBlock" FontSize = "42" TextWrapping = "Wrap">
Hello, <Bold> Xiao Huang </ Bold>, <Italic> wake up today? </ Italic>
</ TextBlock>
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.
<TextBlock Grid.Row = "2" FontSize = "40">
Youku Video <LineBreak /> Tudou Video
</ 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.
<Textblock grid. Row = "2" fontsize = "40"> youku video <linebreak/> Tudou video </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.
<TextBlock Grid.Row = "4" FontSize = "40" TextWrapping = "Wrap">
<Run FontStyle = "Italic"
FontFamily = "Tahoma"
FontSize = "65"
Foreground = "Orange">
Lotus pond moonlight
</ Run>
</ 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.
<Button HorizontalAlignment="Left" Margin="58,68,0,0" Name="button1" VerticalAlignment="Top"
Click="button1_Click">
<Button.Content>
<Ellipse Height="76" Width="125">
<Ellipse.Fill>
<LinearGradientBrush
StartPoint="0,0"
EndPoint="1,1">
<GradientStop Color="Yellow" Offset="0.12"/>
<GradientStop Color="MediumVioletRed" Offset="1"/>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
</Button.Content>
</Button>
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.
<Button HorizontalAlignment="Left" Margin="58,68,0,0" Name="button1" VerticalAlignment="Top" Click="button1_Click"> <Button.Content> <Ellipse Height="76" Width="125"> <Ellipse.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="Yellow" Offset="0.12"/> <GradientStop Color="MediumVioletRed" Offset="1"/> </LinearGradientBrush> </Ellipse.Fill> </Ellipse> </Button.Content> </Button>
Check whether it is interesting after running it?
(Figure 5)
3. checkbox control.
Let alone this. Let's look at the example.
<StackPanel Orientation = "Vertical">
<CheckBox Content = "Chinese cabbage" IsChecked = "True" />
<CheckBox Content = "pear" />
<CheckBox Content = "Apple" IsChecked = "False" />
<CheckBox Content = "flowers" />
</ StackPanel>
(Figure 6)