前言

Border 俗称边框控件,它的核心功能是为另一个单一的子元素提供装饰,例如添加边框、背景、圆角。
1、作为边框
使用边框包裹TextBlock,BorderBrush属性指定边框颜色,BorderThickness指定边框的宽度。
csharp
<Border BorderBrush="Blue" BorderThickness="5" Margin=" 10" >
<TextBlock Text="边框" />
</Border>

2、作为背景
使用边框包裹TextBlock , 如果不设置TextBlock 背景色的话,则使用Border的 Background指定的背景色。
csharp
<Border Background="Yellow" Margin=" 10">
<TextBlock Text="背景" />
</Border>

3、作为圆角
使用边框包裹TextBlock , BorderBrush属性指定边框颜色, BorderThickness指定边框的宽度,CornerRadius指定圆角半径,这里一定要设置Padding,并且Padding的值设置比CornerRadius大一点。
1)Padding不为0(正确使用)
csharp
<Border BorderBrush="Blue" BorderThickness="2" CornerRadius=" 10" Padding="15" Margin=" 10">
<TextBlock Text="圆角" />
</Border>

2)Padding为0(错误使用)
csharp
<Border BorderBrush="Blue" BorderThickness="2" CornerRadius=" 10" Margin=" 10">
<TextBlock Text="圆角" />
</Border>
