Reputation: 995
I Want to set the font of my WPF dialog to similar of an existing Winforms dialog i.e. Microsoft Sans Serif, 8.25pt. How can we specify the Font unit in WPF?
Upvotes: 6
Views: 6010
Reputation: 85957
Just include the text pt
or px
in the font-size. For example,
<TextBlock Width="400" Text="">
<Run FontFamily="Microsoft Sans Serif"
FontSize="8.25 pt">Hello world!</Run>
</TextBlock>
1 pt
is defined as 1/72nd of an inch; 1 px
is 1/96th of an inch.
Note that unit qualifiers are only supported in WPF, not in Silverlight.
There is no equivalent to the CSS unit em
, but there is a workaround.
Upvotes: 8
Reputation: 1612
You can acheive that by setting the FontFamily
and the 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 have set the FontFamily to Microsoft Sans Serif and the FontSize to 8.25 pt. Know that Windows Forms font size = WPF font size * 72.0 / 96.0.
Upvotes: 0
Reputation: 13992
Here is a MSDN article on WPF font sizes;
http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock.fontsize(v=vs.95).aspx
Upvotes: 2