How to use a different coordinate system in WPF? (scaling only)

妖精的绣舞 提交于 2019-12-03 12:58:55

For the outlined requirements you do not need to do anything special at all, just go ahead and use centimeters as unit of measurement for the WPF elements themselves (i.e. without any transform) - the very nature of WPF device independence allows you to to the following:

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

That is: you'll get a A4 window specified in 'cm' with a centered square TextBox specified in 'in' and a font specified in 'pt'. All these will scale properly by whatever transform you might apply additionally, if need be (e.g. via a zoom slider for the users view port), respecting their relative sizes regardless of being specified with different units each (i.e. mixed usage at will).

Available units are px (default), in, cm and pt, see for example FrameworkElement.Height for details on their specification.

You can also set sizes in points (FontSize="10pt"), in inches (FontSize="10in") or in centimeters (FontSize="10cm"). Of course the real size depends on the DPI setting of Windows and the DPI of your monitor or printer in this case.

Just set the font size to 12 / 3.779 = 3.175, no? Assign it to the containing object and it should trickle down to all children.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!