将System.Drawing.Font.Size转换为WPF FontSize

ser*_*hio 6 .net wpf fonts font-size winforms

我需要在WPF"字体"中转换GDI字体.

myGdiFont As System.Drawing.Font
Run Code Online (Sandbox Code Playgroud)

_Family As Windows.Media.FontFamily
_Style As Windows.FontStyle
_Weight As Windows.FontWeight
_Size As Double
Run Code Online (Sandbox Code Playgroud)

特别是,我需要转换

_Size = myGdiFont.Size (???)
Run Code Online (Sandbox Code Playgroud)

WinForms字体的大小是单位或点...在WPF中是像素...如何从一个转换为另一个?

PS.
掌握克莱门斯的迹象,这是正确的吗?

  Dim myDrawingFont As New System.Drawing.Font("Arial", 10)
  Dim myWpfLabel As New Windows.Controls.Label
  myWpfLabel.FontSize = myDrawingFont.SizeInPoints * 72 / 96
Run Code Online (Sandbox Code Playgroud)

固定:

  myWpfLabel.FontSize = myDrawingFont.SizeInPoints * 96 / 72
Run Code Online (Sandbox Code Playgroud)

Cle*_*ens 10

通过乘法.点是1/72英寸,而WPF设备无关单位("WPF像素")是1/96英寸.

您可以通过在XAML中指定WPF控件的FontSize属性来验证这一点,例如"24"和"18pt".您将意识到两个值都会产生相同的实际字体大小.

  • 不,它应该是`myWpfLabel.FontSize = myDrawingFont.SizeInPoints/72*96`. (3认同)