6.1.2 字体
1. 字体家族
| 名称 | 说明 |
|---|---|
| FontFamily | 字体,就是选择宋体,黑体,幼圆等等的属性,当确定FontFamily时,不能使用缩写字符串 |
| FontSize | 字体的设备无关单位尺寸 |
| FontStyle | 可以设置斜体 |
| FontWeight | 设置文本粗细 |
| FontStretch | 设置字体拉伸或压缩程度,UltraCondensed减至正常宽度50% |
| FontStyle | 说明 |
|---|---|
| Italic | 斜体字 |
| Normal | 正常 |
| Oblique | 倾斜的文字 |
Italic是指斜体字,而Oblique是倾斜的文字,对于没有斜体的字体应该使用Oblique属性值来实现倾斜的文字效果
| FontWeight | |
|---|---|
| Black | 黑体 |
| Bold | 加粗 |
| Heavy | 变宽? |
| Light | 瘦身(压扁) |
| Medium | 中等 |
| Normal | 普通模式 |
| Regular | |
| Thin | |
| DemiBold | |
| ExtraBlack | |
| ExtraBold | |
| ExtraLight | |
| SemiBold | |
| UltraBlack |
| FontStretch | |
|---|---|
| Condensed | |
| Expanded | |
| ExtraCondensed | |
| ExtraExpanded | |
| Medium | |
| Normal | 普通 |
| SemiCondensed | |
| SemiExpanded | |
| UltraCondensed | 将字体减至正常宽度的50% |
| UltraExpanded |
2. 文本装饰和排版
有些元素可以通过TextDecorations和Typography属性,支持更高级的文本控制。
例如:
| TextDecoration | 说明 |
|---|---|
| Baseline | |
| Overline | |
| Strikethrough | |
| Underline | 下划线 |
3. 字体继承
当设置任何字体属性时,属性值都会流经嵌套的对象。
4. 字体替换
<Button FontFamily="Technical Italic, Comic Sans MS, Arial" Grid.Row="1" Grid.Column="1"
Margin="40">A Button</Button>
三种字体第一种没有的情况下用第二种,再没有就使用第三种。
5. 字体嵌入
首先向应用程序中添加字体文件(通常是具有.ttf扩展名的文件),并将Build Action选项设置为Resourse(为设置该属性,可在Visual Studio的Solution Explorer中选择字体文件,并在Properties窗口中改变它的Build Action属性)。
接下来在使用字体时,需要在字体家族名称之前添加字符序列“./#”,如下所示:
<Label FontFamily="./#Bayern">...aaa...</Label>
6. 文本格式化模式
<TextBox FontSize="12" Grid.Row="1" Grid.Column="0" Margin="5">This is a Test. Ideal text
is blurry at small sizes.</TextBox>
<TextBox FontSize="12" Grid.Row="1" Grid.Column="1" Margin="5"
TextOptions.TextFormattingMode="Display">This is a Test. Display text is crisp at small
sizes.</TextBox>