如何在WPF中指定字体单位

时间:2011-04-19 08:14:24

标签: c# wpf

我想将我的WPF对话框的字体设置为类似于现有的Winforms对话框,即Microsoft Sans Serif,8.25pt。我们如何在WPF中指定字体单位?

3 个答案:

答案 0 :(得分:6)

只需在font-size中加入文字ptpx即可。例如,

<TextBlock Width="400" Text="">
   <Run FontFamily="Microsoft Sans Serif"
        FontSize="8.25 pt">Hello world!</Run>
</TextBlock>

1 pt定义为1/72 nd 的英寸; 1 px是1/96 th 的英寸。

请注意,单位限定符为only supported in WPF,而不是Silverlight。

没有与CSS单元em等效,但有is a workaround

答案 1 :(得分:1)

答案 2 :(得分:0)

您可以通过设置控件的FontFamilyFontSize属性来实现这一目标。

例如

<UserControl x:Class="FitPredictionModule.Views.BondTestView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

             FontFamily="Microsoft Sans Serif"
             FontSize="8.25 pt">
             <!-- Content here -->
</UserControl>

你可以看到我已将FontFamily设置为Microsoft Sans Serif,将FontSize设置为8.25 pt。知道Windows Forms字体大小= WPF字体大小* 72.0 / 96.0。