WPF控件类(Control)介绍

  • 控件背景与前景

在WPF中,背景和前景分别使用Background和Foreground属性设置这两个区域(但非内容)的颜色。
这些属性使用的是更强大的对象:Brush对象。该对象为填充背景和前景内容提供了灵活性,可使用单一颜色(用SolidColorBrush画刷)或更特殊的颜色(如使用LinearGraidientBrush或TileBrush画刷)填充背景和前景。

设置方式:

<Window x:Class="WpfApp1.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:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100"></RowDefinition>
            <RowDefinition Height="100"></RowDefinition>
            <RowDefinition Height="100"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <!--XAML设置-->
        <!--Background:背景色 Foreground:前景色-->
        <Button Background="Red" Foreground="Yellow" FontSize="30" Content="前景色"></Button>
        <!--C#代码实现-->
        <!--this.btn.Background = new SolidColorBrush(Colors.Red);-->
        <!--this.btn.Foreground = new SolidColorBrush(Colors.Yellow);-->
        <!--this.btn.Background = new SolidColorBrush(Color.FromRgb(0,0,250));  //RGB设置颜色-->
        <!--this.btn.Foreground = new SolidColorBrush(Color.FromRgb(255,0,0));  //RGB设置颜色-->
        <Button Grid.Row="1" Name="btn" FontSize="30" Content="前景色" Click="btn_Click"></Button>
    </Grid>
</Window>
  • 字体属性

FontFamily:字体种类(宋体、黑体)
FontSize:字体大小
FontStyle:字体样式,角度(斜体)
FontWeight:字体粗细
FontStretch:字体拉伸和压缩

  • 字体装饰

基线:TextDecorations=“Baseline”
中划线:TextDecorations=“Strikethrough”
下划线:TextDecorations=“Underline”
顶线:TextDecorations=“OverLine”

  • 字体嵌套字体文件ttf

使用系统没有安装的字体,在项目中添加现有项-字体.ttf文件,文件属性中生成操作修改为Resource,在需要设置字体属性的地方使用FontFamily = "./#字体"即可。

  • 鼠标光标状态

        <!--鼠标光标状态-->
        <!--C#代码实现-->
        <!--this.Cursor = Cursors.Wait;-->
        <Button Grid.Row="2" Name="btn1" Content="鼠标状态Help" Cursor="Help" Click="ChangeCursor"></Button>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值