需要能够在整个应用程序中更改字体大小以实现可访问性 [英] Need to be able to change Font size across an entire application for accesibility

查看:51
本文介绍了需要能够在整个应用程序中更改字体大小以实现可访问性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WPF、MVVM 和 Visual Studio 2015 构建了一个 GIS 路由应用程序.

I have built a GIS routing application, using WPF, MVVM, and Visual Studio 2015.

当我在笔记本电脑上测试应用程序时,字体看起来比我在电脑上以调试模式测试时的字体小.

When I test the app on a laptop, the fonts seem smaller than when I tested in debug mode on my pc.

有没有办法在我的应用程序设置中创建一个功能,以便用户可以在不影响图形的情况下全局增加所有字体的大小?我希望这类似于带有ctrl +"的网页设计.

Is there a way to create a feature in my application settings so a user could increase the size of all of the fonts, globally, without affecting the graphics? I was hoping this would be similar to a webpage design with the 'ctrl +'.

任何帮助将不胜感激.

推荐答案

我使用 ViewBox 向我的应用程序添加了类似的功能.请注意,它不会更改字体大小,而是缩放"用户界面的所有方面.不确定这是否正是您想要的,但这就是给您一个想法的样子:

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:

为了实现这一点,我将最高级别的 View(承载所有内容,这可以在 Window 级别上完成)包装在一个 ViewBox 中,然后将 Width 和 Height 绑定到 ViewModel 中的属性,我可以使用缩放"量:

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>

带宽度和高度:

    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);
        }
    }

这不仅允许应用程序独立于分辨率(所有内容在大 DPI 屏幕上都不会显得很小),而且还允许用户在阅读时遇到问题或只是喜欢它时进行缩放.

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.

很简单.为了仅影响字体大小,您可能应该考虑为组件构建样式模板.我敢打赌,您可以通过简单地使用字体大小设置全局 TextBlock 样式来捕获大量文本 - 不确定默认样式的动态程度.

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.

试试这个样式:

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

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

您可能需要一个 wpf 控件列表(按钮、复选框、文本框等),但这不会太难.

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

BaseFontSize 应该可以改变.如果它在窗口或应用程序资源中,所有没有样式集的控件都将使用它作为默认值.因此,您无需检查所有控件以确保它们具有样式集.

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.

这篇关于需要能够在整个应用程序中更改字体大小以实现可访问性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆