Need to be able to change Font size across an entire application for accesibility

感情迁移 提交于 2019-12-04 18:18:32

I've added similar functionality to my application using ViewBox. Note, it doesn't change the font size, but instead "zooms" all aspects of the user interface. Not sure if this is exactly what you want, but this is what it looks like to give you an idea:

To get this, I wrapped the highest level View (that hosts all content, this could be done on the Window level) in a ViewBox, and then bound the Width and Height to properties in the ViewModel that I could edit using a "zoom" amount:

<Viewbox SnapsToDevicePixels="True" >
    <DockPanel Width="{Binding Width}" Height="{Binding Height}" SnapsToDevicePixels="True">
          ...content...
    </DockPanel>
</ViewBox>

With the width and height:

    private int BaseWidth = 1150;
    private int BaseHeight = 750;

    public int Width
    {
        get
        {
            return (int)(BaseWidth * appSettings.Zoom);
        }
    }

    public int Height
    {
        get
        {
            return (int)(BaseHeight * appSettings.Zoom);
        }
    }

This not only allows the application to be resolution independent (everything wont look tiny on a large DPI screen) it will also allow users to scale if they are having trouble reading things, or if they simply prefer it.

Pretty simple. To effect only font size, you should probably be looking at building style templates for the components. I'd bet you'd catch a lot of the text by simply setting a global TextBlock style with the font size - not sure how dynamic you can be with the default styles.

Edit: Try this with styles:

<sys:Double x:Key="BaseFontSize">12</sys:Double>

<Style TargetType="{x:Type TextBlock}">
    <Setter Property="FontSize" Value="{DynamicResource BaseFontSize}"/>
</Style>

You might have to have a list of wpf controls (buttons, checkboxes, textboxes etc etc) but it wouldn't be too difficult.

BaseFontSize should be able to be changed. All controls without a style set will use this as default if it's in window or app resources. So you won't need to go through all the controls making sure they have a style set.

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