How to specify font blocks in WPF

I want to set the font of my WPF dialog box similarly to the existing Winforms dialog box, i.e. Microsoft Sans Serif, 8.25pt. How can we specify a Font block in WPF?

+4
source share
3 answers

Just enter the text pt or px in the font size. For instance,

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

1 pt defined as 1/72 nd of an inch; 1 px is 1/96 th of an inch.

Please note that qualifier units are only supported in WPF and not in Silverlight.

There is no equivalent to the CSS em block, but there is a workaround there .

+6
source

You can achieve this by setting the FontFamily and FontSize properties of the control.

eg.

 <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> 

You can see that I installed FontFamily in Microsoft Sans Serif and FontSize at 8.25 pt. Be aware that Windows Forms font size = WPF font size * 72.0 / 96.0.

0
source

All Articles