Most WP controls can be inherited from Silverlight. Here I can only demonstrate some of them. For how to use other controls, refer to SDK instructions and Silverlight SDK documentation.
1. radiobutton control.
This is a single-choice control, which does not need to be explained. We have read more about it. If n is selected, whether the control is selected by the user is marked by the ischecked attribute.
In addition, note that the groupname attribute is used to input a group name, which is obtained by ourselves for grouping purposes. Because it is a single choice, A container may have n multiple radiobutton controls or multiple groups of radiobutton controls. Therefore, the group name plays a role, that is, only one group can be selected, for example, there is a group A, and a contains three radiobutton controls, which are respectively red, green, and yellow. Therefore, you can only select one of the three, and another group B, B has a radiobutton control, indicating the black light. Because it belongs to different groups, the red and black lights can be selected at the same time, or the green and black lights can be selected at the same time.
The following is an example:
<Radiobutton content = "pig head" Height = "115" horizontalalignment = "Left" margin = ", 50, 0, 0 "name =" rad01 "verticalignment =" TOP "fontsize =" 43 "width =" 333 "groupname =" g1 "Checked =" radiobtn_checked "/> <radiobutton content =" bull's head "Height =" 115 "horizontalalignment =" Left "margin =" 58,207, 333 "name =" rad02 "verticalignment =" TOP "fontsize =" 43 "width =" "groupname =" g1 "Checked =" radiobtn_checked "/> <radiobutton content =" Dog Header "Height =" 109 "horizontalalignment =" Left "margin =" 58,351, 333 "name =" rad03 "verticalignment =" TOP "fontsize =" 43 "width =" "groupname =" g1 "Checked =" radiobtn_checked "/>
Private void radiobtn_checked (Object sender, routedeventargs e) {radiobutton RDB = E. originalsource as radiobutton; If (RDB! = NULL) {string MsgC = RDB. content as string; If (MsgC! = NULL) {MessageBox. Show ("You selected:" + MsgC );}}}
(Figure 1)
2. Image control.
This guy, you can guess what the name is. Yes, it is used to display images.
This control has two attributes to consider.
1. Source: supports both local images. Of course, it is generally better to compile images as resources. DLL is compressed into the xap package. At the same time, this attribute also supports Network images.
2. Stretch: how to place images in controls.
Example:
<Image HorizontalAlignment="Stretch" Margin="3" Name="image1" Stretch="Fill" VerticalAlignment="Stretch" Source="/ControlsSample2;component/Images/Desert.jpg" />
(Figure 2)
Next, let's take a look at the effect of using different values for the stretch attribute.
(Figure 3 and 4)
It may not be obvious. You can try it on your own.
3. ListBox control.
Even if you have never played WPF, you must have played a lot in winform. Set the itemssource attribute to bind data.
<ListBox HorizontalAlignment="Stretch" Margin="3" Name="listBox1" VerticalAlignment="Stretch" />
This. listbox1.itemssource = new string [] {"Long Teng Hu Yue", "Hu tou shewei", "Ye gonghaolong", ""};
(Figure 5)
4. hyperlinkbutton control.
This control was also mentioned during the introduction of navigation. By the way, you can use it to easily implement page navigation. The example is omitted. It saves several hundred words.