Border 是一个装饰的控件,此控件绘制边框及背景,它有着几个重要的属性
- Background:用用一个 Brush 对象来绘制背景 ;
- BorderBrush:用一个Brush 对象来绘制边框 ;
- BorderThickness:此属性设置 Border 边框的大小;
- CornerRadius:此属性设置 Border 的每一个角圆的半径;
- Padding:此r属性设置 Border 里的内容与边框的之间的间隔
例子:
效果图
上图的border的背景用了图片画笔,边框用了渐变色,边框粗细设置了3,角弧度设置了5,
页面代码如下:
<Window x:Class="wpf实验.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/ 2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:wpf borber"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Border Height="200" Margin="156,59,164.4,61.8" BorderThickness="3" CornerRadius="5" >
<!—border的背景-->
<Border.Background>
<ImageBrush>
<ImageBrush.ImageSource>
<BitmapImage UriSource="/imager\01.jpg"/>
</ImageBrush.ImageSource>
</ImageBrush>
</Border.Background>
<!--边框的渐变色-->
<Border.BorderBrush>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Blue" Offset="0"/>
<GradientStop Color="Red" Offset="0.5"/>
<GradientStop Color="Black" Offset="0.8"/>
</LinearGradientBrush>
</Border.BorderBrush>
</Border>
</Grid>
</Window>