Windows Phone开发(11):常用控件(下)

移动开发
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox Live游戏、Xbox Music音乐与独特的视频体验整合至手机中。

WP控件大部分都可以从Silverlight中继承过来,这里我也只能拿一部分作演示,对于其它控件如何使用,可以参考SDK相关说明以及Silverlight SDK文档。

一、RadioButton控件。

这是一个单选控件,不用多解释,我们见得多了,N选1,控件是否被用户选中,由IsChecked属性标记。
另外,要注意的一点是GroupName属性,它输入一个分组名,这个名由我们自己来取,目的也是为了分组,因为是单选,所以,一个容器中可能有N多个 RadioButton控件或都有多组RadioButton控件,因此,组名就发挥了作用,也就是说,同一个组内的只能选一个,比如,有一个组A,A中 包含3个RadioButton控件,分别为红灯,绿灯,黄灯,因此,这三个之中你只能选择一个,另外有一组B,B中有一个RadioButton控件, 表示黑灯。由于属于不同的组,红灯和黑灯可以同时被选择,或者,绿灯和黑灯可以同时选中。
下面看一个例子:

  1. <RadioButton Content="猪头" Height="115" HorizontalAlignment="Left" Margin="58,50,0,0" Name="rad01" VerticalAlignment="Top" FontSize="43" Width="333" GroupName="G1" Checked="radioBtn_Checked" /> 
  2. <RadioButton Content="牛头" Height="115" HorizontalAlignment="Left" Margin="58,207,0,0" Name="rad02" VerticalAlignment="Top" FontSize="43" Width="333" GroupName="G1" Checked="radioBtn_Checked" /> 
  3. <RadioButton Content="狗头" Height="109" HorizontalAlignment="Left" Margin="58
  1. private void radioBtn_Checked(object sender, RoutedEventArgs e) 
  2.     RadioButton rdb = e.OriginalSource as RadioButton; 
  3.     if (rdb != null
  4.     { 
  5.         string msgc = rdb.Content as string
  6.         if (msgc != null
  7.         { 
  8.             MessageBox.Show("你选择了:" + msgc); 
  9.         } 
  10.     } 

(图1)

二、Image控件。

这个家伙,看名字你也猜到它是干啥的。呵呵,对的,它就是用于显示图片的。

该控件有两个属性要关心。
1、Source:既支持本地图片,当然,一般把图片编译为资源好一些,这样它就和.dll一起压缩进xap包里面了;同时,该属性也支持网络图片。
2、Stretch:图片在控件中如何放置。

如下面的例子:

  1. <Image HorizontalAlignment="Stretch" Margin="3" Name="image1" Stretch="Fill" VerticalAlignment="Stre 

(图2)

 

接下来我们看看,Stretch属性取不同的值会有什么效果。
(图3、4)

可能不明显,大家可以自己动手试试。

三、ListBox控件。

就算你没玩过WPF,在WinForm里面你肯定耍得不少了,绑定数据请设置ItemsSource属性。

  1. <ListBox HorizontalAlignment="Stretch" Margin="3" Name="listBox1" VerticalAlignment="Stretch"  /> 
  2.         this.listBox1.ItemsSource = new string[] 
  3.         { 
  4.             "龙腾虎跃""虎头蛇尾""叶公好龙""水落石出" 
  5.         }; 

(图5)

四、HyperlinkButton控件。

在介绍导航的时候也提到过这个控件了,对了,用它可以轻松地实现页面导航,例子就省略了吧,呵呵,又节约了几百个字。

责任编辑:闫佳明 来源: oschina
相关推荐

2013-04-17 11:00:17

Windows PhoWindows Pho

2012-02-02 16:37:51

Silverlight常用控件

2013-04-12 11:02:50

WWindowsPho

2013-04-17 14:19:51

Windows PhoWindows Pho

2010-06-11 16:01:26

Windows Pho

2012-08-09 13:39:22

Windows Pho

2012-08-13 09:56:45

Windows Pho

2010-08-10 13:21:41

Windows PhoWindows Pho

2010-12-01 13:55:29

地图插件Windows Pho

2013-04-19 10:14:24

2010-12-01 13:40:13

枢轴控件Windows Pho

2010-04-21 17:07:54

Windows Pho

2010-12-01 09:50:21

全景视图Windows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概论

2013-07-30 11:18:37

Windows PhoWindows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2011-06-07 12:42:15

Windows Pho

2010-04-08 17:40:23

Windows Pho
点赞
收藏

51CTO技术栈公众号