locked
FontSize Resource using pt? RRS feed

  • Question

  • I want to define a global resource which allows me to define the default font size for some of my controls. But I want to set this value using pt (Point) values instead of px (Pixel).
    For pixels it's not really a problem as shown below:

        <Window.Resources> 
            <sys:Double x:Key="DefaultFontSize">20</sys:Double> 
         
            <Style TargetType="{x:Type Label}"
                <Setter Property="FontSize" Value="{StaticResource DefaultFontSize}" /> 
            </Style> 
        </Window.Resources> 

    Anyone got an idea how I can get the whole thing going with pt Values? Any converters I missed or a special datatype?

    Thanks
    Thursday, September 18, 2008 2:31 PM

Answers

  • From the docs for TextElelemt.FontSize:-

    XAML Values

    double

    Double

    String representation of a Double value equal to or greater than 0.0 but smaller than PositiveInfinity. An unqualified value is measured in device independent pixels. Strings need not explicitly include decimal points.

    qualifiedDouble

    A double value as described above, followed by one of the following unit specifiers: px, in, cm, pt.

    px (default) is device-independent units (1/96th inch per unit)

    in is inches; 1in==96px

    cm is centimeters; 1cm==(96/2.54) px

    pt is points; 1pt==(96/72) px



    -- Michael

    Thursday, September 18, 2008 9:02 PM