对于概述的要求,您根本不需要做任何特别的事情,只需继续使用厘米作为 WPF 元素本身的测量单位(即没有任何转换) - WPF 设备独立性的本质允许您执行以下操作:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="29.7cm" Width="21cm" FontSize="16pt">
<Grid>
<TextBlock Text="Sample" Height="1in" Width="1in" FontSize="12pt"
HorizontalAlignment="Center" VerticalAlignment="Center"
TextAlignment="Center"/>
</Grid>
</Window>
即:您将获得一个在“ ”中指定的 A4 窗口,其中在“ cm
”中指定了一个居中的方形文本框,在“ in
”中指定了一个字体pt
。如果需要,所有这些都将通过您可能额外应用的任何变换正确缩放(例如,通过用户视口的缩放滑块),尊重它们的相对大小,而不管每个都使用不同的单位指定(即随意混合使用)。
Available units are px
(default), in
, cm
and pt
, see for example FrameworkElement.Height for details on their specification.