综合编程

Narrator reads collapsed content

微信扫一扫,分享到朋友圈

Narrator reads collapsed content
0 0

Last week, I worked on some accessibility issues. One of them was the windows narrator reading collapsed content. Hidding the content from the narrator was a little harder than I would have expected when starting working on the issues.

The WPF application is using an MVVM pattern where controls are hidden and shown by changing the Visibility property. For normal use, this works fine. However, when navigating the screen with the windows narrator, the collapsed content was still read to the user. When looking into the documentation, content in WPF that is collapsed is removed from the visual tree and should not be read by the narrator. As digging deeper it seems to be a bug in the Framework version we were using. Unfortunately, we can’t dictate to our users what framework version to use. .NET Framework version 4.8 will fix the bug, but our users will use the application from 4.7.1.

Fortunately, I found some hints to make a workaround. By overriding the OnCreateAutomationPeer
method, you can give a hint to the narrator to read or not read the element. The method IsControlElementCore
in the AutomationPeer
class gives a hint on if a control is a Control element if so the narrator skips the control. This can be used to skip your content when hidden:

public class MyButton : Button
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new MyAutomationPeer(this);
    }
}

public class MyAutomationPeer : ButtonBaseAutomationPeer
{
     public MyAutomationPeer(Button button): base(button) {}

     protected override bool IsControlElementCore()
     {
          return Owner.Visible != Visiblity.Collapsed;
     }
}

In the XAML I updated the controls to my own controls and now the collapsed content is hidden from the narrator. When we are able to only support .NET Framework 4.8 the custom implementations can be removed from the code base. Till then the workaround makes the page accessible for screen readers.

感谢您的支持!

    数据结构——Golang实现堆栈

    上一篇

    消息称新款 iPad 和 AirPods 2 将于今年上半年登场

    下一篇

    您也可能喜欢

    评论已经被关闭。

    插入图片

    热门分类