开发者

Set WPF Font size based on screen size

I'd like to have a default font size that is based on the users screen resolution. ie if screen work area width is less than 1024 use font size 10 else use font size 14. Am currently using the "SystemParameters.WorkArea.Width" to determine the width

I can set a global font size and have a converter to return a font size, but am really struggling to work out how to make it fire. ie. when the window size changes, make it check what the font size should be

<Window.Resources>

    <local:SetFontSize x:Key="myConverter" />

    <Style TargetType="{x:Type Control}" x:Key="baseStyle">
        <Setter Property="FontSize" Value="14"  />
        <Setter Property="FontFamily" Value="Calibri" />           

</Window.Resources>

I have found the below event, but just can't seem to link the two together (although I might be going about this wrong way)

<Window.Triggers>
    <EventTrigger RoutedEvent="SizeChanged">          
    </EventTrigger>
</W开发者_C百科indow.Triggers>


Why would you want this anyway? Wpf uses abstract coordinates, and convert them to pixels using the current Monitor DPI and resolution. So, your application should automatically scale to look similar on every screen. I would suggest, using stretchy layout, with scrollbars, etc. To enabled your app being used on smaller screens.


Bear in mind that WPF apps are 'DPI-aware' and font sizes are not in pixels - so if the user uses a different DPI setting to increase font size, it will be reflected in your WPF app automatically. Hopefully it's a possibility for users to use the DPI setting as they should?

(If other apps use font size 10 and it's too small, rather than rewrite that app they'd probably adjust their DPI - if no other apps use font size 10, it's probably too small for all users)

I realise this is a non-answer, but it's a shame to sacrifice design and have to hack stuff in for a people who won't adjust their DPI setting? Am I being too negative? :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜