1、Lable 介绍
官方释义:表示包含一段任意类型内容的控件。也可以叫标签控件。
Label控件和TextBlock看起来非常像。但在使用时就会发现,Label使用的是Content属性而不是Text属性。这是因为Label是一个ContentControl,这意味着它可以包含任何类型 (的单个对象,例如字符串、图像或面板) ,而不仅仅是文本。
**************************************************************************************************************
2、Lable 常用属性
Background:背景; Foreground前景色(字体颜色)
BorderBrush:用于描述控件的边框背景的画笔。
BorderThickness:获取或设置控件的边框宽度。
Content:获取或设置 ContentControl 的内容。
FontFamily:获取或设置控件的字体系列。
FontSize:获取或设置字号。
FontStretch:获取或设置字体在屏幕上紧缩或加宽的程度。
FontStyle:获取或设置字体样式。
FontWeight:获取或设置指定字体的粗细。
Width/Height:宽度/高度。 IsEnabled:使能是否可用。 Name:元素标识名称。
Opacity:透明度。 Margin:元素的外边距。
HorizontalAlignment/VerticalAlignment:获取或设置在父元素(如面板或项控件)中组合此元素时所应用的水平/垂直对齐特征。
HorizontalContentAlignment/VerticalContentAlignment:获取或设置控件内容的水平/垂直对齐方式。
**************************************************************************************************************
3、具体示例代码
<!--示例代码一-->
<Grid>
<Label Margin="10" Foreground="#dddddd" BorderBrush="Teal" BorderThickness="1" FontSize="15" FontFamily="微软雅黑" FontStretch="Normal">
<TextBlock Text="入我相思门,知我相思苦,长相思兮长相忆,短相思兮无穷极,早知如此绊人心,还如当初不相识。" TextWrapping="Wrap" />
</Label>
</Grid>
<!--示例代码二-->
<Grid>
<Label Margin="10" Foreground="#dddddd" BorderBrush="Teal" BorderThickness="1" FontSize="15" FontFamily="微软雅黑" FontStretch="Normal">
<StackPanel Orientation="Horizontal">
<Image Width="130" Height="80" Margin="0 10" Source="./huahua.png" Stretch="Fill"/>
<Image Width="130" Height="80" Margin="10 10 0 10" Source="./huahua.png" Stretch="Fill"/>
</StackPanel>
</Label>
</Grid>
<!--示例代码三 Label 设置文本内容水平居中,垂直居中显示-->
<Grid>
<Label Height="60" Foreground="#dddddd" FontSize="13" VerticalAlignment="Center" BorderThickness="1"
Content="早知如此绊人心,还如当初不相识。" Background="Teal" BorderBrush="YellowGreen"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</Grid>
**************************************************************************************************************
4、示例代码效果图,左图为示例代码一效果图;右图为示例代码二效果图;第三张图为代码示例三的效果图
**************************************************************************************************************
5、总结和扩展
在大多数情况下,标签控件它充当另一控件的文本标签,这就是它的主要目的。对于大多数其他情况,应该使用TextBlock控件或WPF提供的其他文本容器之一。
**************************************************************************************************************