初学Silverlight2最好对控件有个大体的了解,因为控件介绍大多类同,所以整理如下,仅供初学者参考
特此声明:内容采自Silverlight之家(http://hi.baidu.com/ycxiangyun/blog)
一、Silverlight2.0基本控件之——Button:
属性:
Content - 按钮上显示的内容
Click - 按钮的单击事件
Cursor - 鼠标移动到按钮上面时,鼠标指针的样式
Arrow - 箭头
Hand - 手形
Wait - 沙漏
IBeam - “I”字形
Stylus - 点
Eraser - 橡皮
None - 无
Padding - 容器内的内容与容器边缘的填充距离(像素值:上下左右;左右,上下;左,上,右,下)
IsEnabled - 按钮是否有效
Button.Content - 按钮上显示的内容
ClickMode - 触发单击事件的类型 [System.Windows.Controls.ClickMode枚举]
ClickMode.Press - 鼠标左键单击
ClickMode.Release - 鼠标左键单击并放开
ClickMode.Hover - 鼠标经过
二、Silverlight2.0基本控件之——Border:
属性:
BorderThickness - 边框的宽度(像素值:上下左右;左右,上下;左,上,右,下)
BorderBrush - 边框的颜色
CornerRadius - 边框角的半径
Border.BorderBrush - 继承自 System.Windows.Media.Brush 的对象
代码如下:
<Border BorderThickness="3" CornerRadius="10" Width="120" Margin="5">
<TextBlock Text="红色Border" ToolTipService.ToolTip="红色Border" TextAlignment="Center" />
<Border.BorderBrush>
<ImageBrush ImageSource="http://silverlight.net/Themes/silverlight/images/logo.jpg" />
</Border.BorderBrush>
</Border>
三、Silverlight2.0基本控件之——Calendar:
属性:
SelectedDatesChanged - 选中日期后所触发的事件
DisplayDateEnd - 此日期之后的日期不予显示
DisplayDateStart - 此日期之前的日期不予显示
FirstDayOfWeek - 控件所显示的每星期的第一天为星期几 [System.DayOfWeek枚举]
DisplayMode - 控件的显示模式 [System.Windows.Controls.DisplayMode枚举]
DisplayMode.Month - 标题显示年月,内容显示日期。默认值
DisplayMode.Year - 标题显示年,内容显示月
DisplayMode.Decade - 标题显示一个十年的区间,内容显示年
IsTodayHighlighted - 是否高亮显示今天的日期
Calendar.SelectedDate - 选中的日期
Calendar.SelectedDates - 选中的多个日期集合
Calendar.BlackoutDates.Clear() - 清除 不允许选择的日期集合 的设置
四、Silverlight2.0基本控件之——CheckBox:
属性:
IsChecked - 是否被选中
IsThreeState - 是否是 有3个状态 的CheckBox
false - 通常的两状态。默认值
true - 有3个状态,分别为:true, false, null。也就是说 CheckBox.IsChecked 是 bool? 类型
IsEnabled - CheckBox是否有效
CheckBox.Content - CheckBox所对应的内容
Checked - 被选中后所触发的事件
Unchecked - 被取消选中后所触发的事件
Click - 被单击后所触发的事件
代码:
<StackPanel>
<CheckBox x:Name="chk1" Content="我是CheckBox" IsChecked="False" Margin="5" />
<CheckBox x:Name="chk2" Content="红色的三状态的CheckBox" Background="Red" IsThreeState="True" Margin="5" />
<CheckBox x:Name="chk3" Content="无效的CheckBox" IsEnabled="False" Margin="5"/>
<CheckBox x:Name="chk4" Margin="5">
<CheckBox.Content>
<Image Source="Logo.jpg" Width="100" />
</CheckBox.Content>
</CheckBox>
</StackPanel>
五、Silverlight2.0基本控件:DatePicker :
属性:
TextBox 结合 Calendar,经典的选择日期的方式
SelectedDateFormat - 被选中的日期的显示格式 [System.Windows.Controls.DatePickerFormat枚举]
SelectedDateFormat.Short - 简短格式。默认值。如2008-10-10
SelectedDateFormat.Long - 非简短格式。如2008年10月10日
代码:
<basics:DatePicker Width="200" SelectedDateFormat="Short"></basics:DatePicker>
六、Silverlight2.0基本控件:HyperlinkButton:
属性:
NavigateUri - 超级链接的目标地址
TargetName - 目标名
HyperlinkButton.Content - 超级链接所显示的内容
代码:
<HyperlinkButton NavigateUri="http://news.sina.com.cn/z/ymyss/" TargetName="_blank" Margin="5" Width="200">
<HyperlinkButton.Content>
<TextBlock Text="中国人的"></TextBlock>
</HyperlinkButton.Content>
</HyperlinkButton>
七、Silverlight2.0基本控件:Image:
属性:
Source - 程序目录下的图片文件地址
Source - 程序集内的图片文件地址 [/程序集名;component/图片路径]
Source - 互联网的图片文件地址
八、Silverlight2.0基本控件:ListBox:
属性:
SelectionChanged - ListBox中某个对象被选中后所触发的事件
代码:
<StackPanel HorizontalAlignment="Left">
<ListBox Margin="5" Width="200" Height="100" SelectionChanged="ListBox_SelectionChanged">
<ListBoxItem Content="ListBoxItem01" />
<ListBoxItem Content="ListBoxItem02" />
<ListBoxItem Content="ListBoxItem03" />
<ListBoxItem Content="ListBoxItem04" />
<ListBoxItem Content="ListBoxItem05" />
<ListBoxItem Content="ListBoxItem06" />
<ListBoxItem Content="ListBoxItem07" />
<ListBoxItem Content="ListBoxItem08" />
<ListBoxItem Content="ListBoxItem09" />
<ListBoxItem Content="ListBoxItem10" />
</ListBox>
<!--
ListBox中可以包含任何对象
-->
<ListBox Margin="5" Width="200">
<TextBlock Text="TextBlock" />
<TextBox Text="TextBox" />
<Button Content="Button" />
</ListBox>
</StackPanel>
九、Silverlight2.0基本控件:RadioButton:
属性:
GroupName - RadioButton控件所属组的组名
Checked - 被选中后所触发的事件
Click - 被单击后所触发的事件
IsEnabled - RadioButton是否有效
IsChecked - 是否被选中
RadioButton.Content - RadioButton所对应的内容
代码:
<RadioButton GroupName="groupName" Margin="5" IsChecked="true">
<RadioButton.Content>
<Image Source="/Silverlight20;component/Images/Logo.jpg" Width="200" />
</RadioButton.Content>
</RadioButton>
十、Silverlight2.0基本控件:PasswordBox:
属性:
Password - PasswordBox控件的密码值
PasswordChar - PasswordBox控件所显示的密码替代字符。默认值为“●”
代码:
<PasswordBox Width="200" PasswordChar="*"></PasswordBox>