您的位置:首页 > 其它

Silverlight 按钮类控件和选择控件 示例

2010-02-13 14:50 239 查看
下面我们开始走一边Silverlight中的基础控件。使用的环境是:Win7 + Visual Studio 2010 RC 因为下面主要去记忆的就是控件的XAML 元素及属性的解释。任何知识开始都是死记硬背的,没有捷径当时间久了,就会熟悉并灵活适用。

 

按钮类控件

Button

Button 控件继承ButtonBase 是最基础的输入控件,通常我们就是点击他,从而触发Click事件所对应的委托方法,来处理用户交互。
可以通过工具栏拖拽一个Button按钮,也可以直接编写XAML代码


<Button Background="AliceBlue" Content="按钮" x:Name="Button3"  Click="Button3_Click" />

HyperlinkButton

HyperlinkButton 的功能是显示一个超链接和<a>标记的功能相同,其中NavigateUri属性用来设置链接地址,TargetName用来设置打开方式
<HyperlinkButton Content="链接按钮名"NavigateUri="http://www.silverlight.net"TargetName="_blank"Canvas.Top="60" Canvas.Left="10"/>

选择类控件

CheckBox

CheckBox控件,如上图效果大家都很熟悉,就是复选框
<!--有D三y种?状′态?的?选?择?框ò--><CheckBox Name="checkBox2" Content="有D三y种?状′态?的?选?择?框ò" IsThreeState="True"Grid.Row="2" Margin="5,5,0,5" Checked="CheckBox_Checked"Unchecked="CheckBox_Unchecked"Indeterminate="CheckBox_Indeterminate"/>
IsThreeState="True" 用来表示支持三种状态

RadioButton

RadioButton 单选框,只能选一组中的一个为选中
<RadioButton Name="rb_group2_1" Content="第ú一?组é-选?项?1"GroupName="FirstGroup" Grid.Row="1"Margin="10,0,0,0" Checked="RadioButton_Checked"/><RadioButton Name="rb_group2_2" Content="第ú一?组é-选?项?2"GroupName="FirstGroup" Grid.Row="2"Margin="10,0,0,0" Checked="RadioButton_Checked"/>GroupName="FirstGroup" 这个属性中的值代表他们属于同一个组
 

ComboBox

ComboBox 下拉列表框,由不可编辑的文本框加上一个单选列表组成。
<ComboBox Name="fontSizeComboBox" Width="80" Grid.Row="0" Grid.Column="3"SelectionChanged="ComboBox_SelectionChanged"><ComboBoxItem Content="12"/><ComboBoxItem Content="13"/><ComboBoxItem Content="14"/><ComboBoxItem Content="15"/><ComboBoxItem Content="16"/></ComboBox>
  

ListBox

ListBox 列表框,可多选也可以单选
 <ListBox Name="listBox1" Height="200" Grid.Row="0" Margin="5,0,5,0"SelectionChanged="ListBox_SelectionChanged"><ListBoxItem Content="列D表í项?1"/><ListBoxItem Content="列D表í项?2"/><ListBoxItem Content="列D表í项?3"/><ListBoxItem Content="列D表í项?4"/><ListBoxItem Content="列D表í项?5"/><ListBoxItem Content="列D表í项?6"/></ListBox>
[code]
[/code]

Slider

滑动控件,可以横向摆放也可以纵向摆放
<Slider Name="verSlider" Grid.Row="3" Orientation="Vertical"Height="200" HorizontalAlignment="Left"Minimum="1" Maximum="10" IsDirectionReversed="True"/>
上面属性的含义是,纵向摆放,位置靠左,最小值1,最大值10,IsDirectionReversed="True" 这个属性代表数值的起始点在上面,终点在下面。 备注控件相对简单,就不放代码了,学习控件的属性说明有一个非常好的方法,就是Blend的时候,输入属性都立即给出提示,非常方便理解,不妨尝试一下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: