前言:Silverlight 2.0 Beta1 已经发布,加入了许多激动人心的新特性:WPF UI 框架、丰富的控件、丰富的网络支持、丰富的基础类库支持等。这是本人的学习笔记,写的比较乱,因此定名为乱弹琴 Silverlight 2.0 系列文章。
上一篇介绍了一些基本控件,这节继续。
Border:
继承层次:
System.Object
System.Windows.DependencyObject
System.Windows.FrameworkElement
System.Windows.UIElement
System.Windows.Controls.Border
示例:
<Canvas x:Name="cvs1">
<Border BorderBrush="Red" x:Name="bor" CornerRadius="15,15" BorderThickness="2">
<Image Source="1.jpg" Margin="20"></Image>
</Border>
</Canvas>
BorderBrush:变框的颜色;CornerRadius:圆角的像素;BorderThickness:边界的宽度。
运行效果:

编程实现:
Border b = new Border();
b.BorderBrush = new SolidColorBrush(Colors.Red);
b.BorderThickness = new Thickness(2);
b.CornerRadius = new CornerRadius(15, 15, 15, 15);
Image img = new Image();
BitmapImage bi = new BitmapImage();
bi.UriSource = new Uri("1.jpg", UriKind.Relative);
img.Source = bi;
img.Margin = new Thickness(20);
b.Child = img;
this.cvs1.Children.Add(b);
b.BorderBrush = new SolidColorBrush(Colors.Red);
b.BorderThickness = new Thickness(2);
b.CornerRadius = new CornerRadius(15, 15, 15, 15);
Image img = new Image();
BitmapImage bi = new BitmapImage();
bi.UriSource = new Uri("1.jpg", UriKind.Relative);
img.Source = bi;
img.Margin = new Thickness(20);
b.Child = img;
this.cvs1.Children.Add(b);
Slider:
继承层次:
System.Object
System.Windows.Controls.Control
System.Windows.Controls.RangeBase
System.Windows.DependencyObject
System.Windows.FrameworkElement
System.Windows.UIElement
System.Windows.Controls.Slider
示例:
<Canvas x:Name="cvs1" Background="DarkGreen">
<TextBox x:Name="txt1" Canvas.Top="20"
Canvas.Left="50" Width="100">
</TextBox>
<Slider x:Name="sld1" Canvas.Top="50"
Canvas.Left="50" Width="200"
Maximum="255" Minimum="0"
ValueChanged="sld1_ValueChanged">
</Slider>
</Canvas>
<TextBox x:Name="txt1" Canvas.Top="20"
Canvas.Left="50" Width="100">
</TextBox>
<Slider x:Name="sld1" Canvas.Top="50"
Canvas.Left="50" Width="200"
Maximum="255" Minimum="0"
ValueChanged="sld1_ValueChanged">
</Slider>
</Canvas>
private void sld1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
txt1.Text = ((int)sld1.Value).ToString();
}
运行效果:

ScrollViewer:
继承层次:
System.Object
System.Windows.Controls.ContentControl
System.Windows.Controls.Control
System.Windows.DependencyObject
System.Windows.FrameworkElement
System.Windows.UIElement
System.Windows.Controls.ScrollViewer
示例:
运行效果:

结束语:
基本控件使用方法比较简单,常用的属性不多,但基本控件使用方法多样,可以在基本控件中插入其他基本控件,风格样式丰富多彩,自定义程度高。
下一篇介绍布局控件。
{
txt1.Text = ((int)sld1.Value).ToString();
}
运行效果:

ScrollViewer:
继承层次:
System.Object
System.Windows.Controls.ContentControl
System.Windows.Controls.Control
System.Windows.DependencyObject
System.Windows.FrameworkElement
System.Windows.UIElement
System.Windows.Controls.ScrollViewer
示例:
<ScrollViewer Background="Orange" Height="160" Width="200" HorizontalScrollBarVisibility="Visible">
<TextBlock Width="200" Height="300">
this is a test!
this is a test!
this is a test!
this is a test!
this is a test!
</TextBlock>
</ScrollViewer>
<TextBlock Width="200" Height="300">
this is a test!
this is a test!
this is a test!
this is a test!
this is a test!
</TextBlock>
</ScrollViewer>
运行效果:

结束语:
基本控件使用方法比较简单,常用的属性不多,但基本控件使用方法多样,可以在基本控件中插入其他基本控件,风格样式丰富多彩,自定义程度高。
下一篇介绍布局控件。
浙公网安备 33010602011771号