WPF 字体基本属性

开发工具与关键技术:MVC、WPF
作者:刘俊杰
撰写时间:2019年05月16日
字体的属性不多,常用的就只有FontSize(字体大小)、FontWeight(字体加粗)、FontFamily(字体)、Foreground(字体颜色)这几种属性。字体属性用起来也很简单,只需要将字体的属性加入相应的控件中去就行了。

下面我们通过代码来了解一下字体的属性:

<Window x:Class="WpfApplication1.字体属性"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="字体属性" Height="300" Width="300">
    <Grid>
        <TextBlock Foreground="Red">字体颜色</TextBlock>
        <TextBlock FontWeight="Bold" Margin="0,20,0,0">字体加粗</TextBlock>
        <TextBlock FontSize="18" Margin="0,40,0,0">字体大小</TextBlock>
        <TextBlock FontFamily="宋体" Margin="0,70,0,0">字体</TextBlock>
    </Grid>
</Window>

显示的结果:
在这里插入图片描述
字体属性除了直接加在对应的控件中,还可以定义Style样式,在Style样式中改变文字的样式。

下面是引用样式代码:

<Window x:Class="WpfApplication1.字体属性"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="字体属性" Height="300" Width="300">
    <!--资源-->
    <Window.Resources>
        <!--样式-->
        <Style x:Key="Font" TargetType="TextBlock">
            <Setter Property="FontSize" Value="18"></Setter>
            <Setter Property="Foreground" Value="Red"></Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <TextBlock>字体样式</TextBlock>
        <TextBlock Style="{StaticResource Font}" Margin="0,20">字体样式</TextBlock>
    </Grid>
</Window>

显示结果:
在这里插入图片描述

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值