siilverligt中所有的控件类都是FrameworkElement的子类,可以分为面板控件:比如canvas,grid控件等,内容控件:BUTTON控件等,列表控件:COMBOBOX,LISTBOX控件等,普通控件:TEXTBOX,PASSWORDTEXTBOX控件;其他控件:IMAGE控件等....
根据控件的功能不同,下面又可以分为几类:
命令控件:Button,HyperlinkButton控件等
文本编辑控件:TEXTBOX,PASSWORDBOX控件
选择控件:CHECKBOX,RADIOBUTTON控件
列表控件,日期控件,信息显示控件,多媒体控件,数据显示控件,布局控件,下面我就一一给大家演示,并分享源码,让大家都能体验到SL之美,由于本人只有晚上有时间,所有进度有点慢啊,希望大家能理解一下,嘿嘿.
命令控件:BUTTON控件,REPEATBUTTON,HYPERLINKBUTTON
button控件:大家都很熟悉吧,和.NET的按钮差不多,来看使用吧
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Background="White" VerticalAlignment="Center">
<Button x:Name="btnrelease" ClickMode="Release" Content="释放" Click="btnrelease_Click" Width="200" Height="50" Margin="10"></Button>
<Button x:Name="btnpress" ClickMode="Press" Content="按下" Click="btnpress_Click" Width="200" Height="50" Margin="10"></Button>
<Button x:Name="btnhover" ClickMode="Hover" Content="悬停" Click="btnhover_Click" Width="200" Height="50" Margin="10"></Button>
</StackPanel>
<StackPanel Background="White" VerticalAlignment="Center">
<RepeatButton Content="响应重复单击事件" Click="RepeatButton_Click" Width="250" Delay="500" Interval="800" Margin="10" Height="40"></RepeatButton>
<TextBlock x:Name="clickcont" Text="点击次数:"></TextBlock>
</StackPanel>
<StackPanel Background="White" VerticalAlignment="Center">
<HyperlinkButton NavigateUri="http://www.cnblogs.com/" TargetName="_blank" Content="连接"></HyperlinkButton>
</StackPanel>
</Grid>
button控件是内容控件可以自定义效果,你建立个SL项目试下就OK了,效果简直就是美啊,在看后台的CS文件
private void btnrelease_Click(object sender, RoutedEventArgs e)
{
this.btnrelease.Background = new SolidColorBrush(Colors.Red);
}
private void btnpress_Click(object sender, RoutedEventArgs e)
{
this.btnpress.Background = new SolidColorBrush(Colors.Green);
}
private void btnhover_Click(object sender, RoutedEventArgs e)
{
this.btnhover.Background = new SolidColorBrush(Colors.Orange);
}
int count = 0;
private void RepeatButton_Click(object sender, RoutedEventArgs e)
{
count += 1;
this.clickcont.Text = "点击次数"+count;
}
注意:BUTTON按钮的CLICK事件模式由它的CLICKMODE属性来决定的,共有3个选项
Release:释放鼠标时发生
Press:按下时发生
Hover:鼠标悬停发生
RepeateButton特有的属性:Delay:获取或设置被按下后在开始重复点击前等待的时间,INTERVAL:获取或设置重复开始后单击操作的重复时间间隔.
HyperlinkButton属性:NavigateURi tragetName 这个就不用我给大家讲了三,大家都能明白的吧
RepeateButton:这个控件很牛来看效果就知道了.上面代码都给了试下就知道了
文本编辑控件:Textbox,PasswordBOx
<StackPanel Background="White" VerticalAlignment="Center">
<TextBox Width="300" Height="100" Margin="10"></TextBox>
<TextBox x:Name="txtinput" Width="300" Height="100" Margin="10" AcceptsReturn="True" SelectionChanged="TextBox_SelectionChanged"></TextBox>
<TextBox Width="300" Height="100" Margin="10" IsReadOnly="True" Text="只读"></TextBox>
<TextBox Width="300" Height="100" Margin="10" IsEnabled="False" Text="不可用"></TextBox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="btnforg" Width="100" Height="35" Margin="10" Content="前景色" Click="btnforg_Click"></Button>
<Button x:Name="btnbacg" Width="100" Height="35" Margin="10" Content="背景色" Click="btnbacg_Click"></Button>
<TextBlock x:Name="showfont" Text="选择的字数:" VerticalAlignment="Center"></TextBlock>
</StackPanel>
private void TextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
this.showfont.Text = "选择的字数:"+this.txtinput.SelectionLength;
}
private void btnforg_Click(object sender, RoutedEventArgs e)
{
this.txtinput.SelectionForeground=new SolidColorBrush(Colors.White);
}
private void btnbacg_Click(object sender, RoutedEventArgs e)
{
this.txtinput.SelectionBackground = new SolidColorBrush(Colors.Red);
}
属性讲解:textbox:AccepetReturn是否自动换行,Isreadonly是否只读,Isenabled是否禁用按钮,其中selectedtext表示选中的内容,selectionLength选中的字符数长度,其他的我就不多讲了,大家都能理解吧,
下面就来在看个很有用的实例吧(用TEXTBOX实现的水印效果)
<StackPanel Background="White" VerticalAlignment="Center">
<TextBox x:Name="txtname" Height="35" Width="300" Margin="10" Text="请输入用户名" Foreground="LightGray" GotFocus="txtname_GotFocus" LostFocus="txtname_LostFocus"></TextBox>
</StackPanel>
<StackPanel Background="White" VerticalAlignment="Center">
<PasswordBox x:Name="password1" Width="300" Height="30" Margin="10" PasswordChar="*"></PasswordBox>
<PasswordBox x:Name="pwd" Width="300" Height="30" Margin="10" PasswordChar="#"></PasswordBox>
<Button x:Name="get" Width="300" Height="30" Margin="10" Content="获取" Click="get_Click"></Button>
<TextBlock x:Name="pwdtxt"></TextBlock>
</StackPanel>
private void txtname_GotFocus(object sender, RoutedEventArgs e)
{
this.txtname.Text = "";
this.txtname.Foreground = new SolidColorBrush(Colors.Red);
}
private void txtname_LostFocus(object sender, RoutedEventArgs e)
{
if (this.txtname.Text == string.Empty)
{
this.txtname.Text = "请输入用户名";
this.txtname.Foreground = new SolidColorBrush(Colors.LightGray);
}
}
private void get_Click(object sender, RoutedEventArgs e)
{
pwdtxt.Text = "你输入的密码是"+password1.Password;
}
好了,今天就写到这里,明天继续啊......