【问题标题】:Windows Narrator reads the names of all the controls in the window (even hidden ones)Windows 讲述人读取窗口中所有控件的名称(甚至是隐藏的)
【发布时间】:2013-08-08 16:26:27
【问题描述】:
我需要让我的应用程序对视觉障碍者友好......我正面临这个问题:Windows 讲述人会读取窗口中的所有控件名称,尽管其中一些控件名称是隐藏的。
我有另一个应用程序,我使用 WinForms 编写它,它运行良好。
查看 UI Spy 后,我看到 WinForms 应用程序没有公开隐藏的控件,而 WPF 正在公开窗口中的所有控件。
会不会是 WPF 的 bug?
【问题讨论】:
标签:
wpf
xaml
wpf-controls
hidden-field
narrator
【解决方案1】:
我遇到了同样的问题。
根据亚历克西斯的回答,我写了下面的代码。它对我有用。
public class MyAutoComplete : RadAutoCompleteBox
{
public MyAutoComplete ()
{
//init stuff here
}
protected override AutomationPeer OnCreateAutomationPeer()
{
return new MyAutomationPeer(this);
}
}
internal class MyAutomationPeer : RadAutoCompleteBoxAutomationPeer
{
public MyAutomationPeer(FrameworkElement owner)
: base(owner)
{
}
protected override List<AutomationPeer> GetChildrenCore()
{
return new List<AutomationPeer>();
}
}
【解决方案2】:
如果您的控件已经在可视化树中,这种行为是正常的,因为 UI 自动化树基于可视化树。因此,如果您想防止使用屏幕阅读器阅读不必要的元素,则必须按需加载它们。
您还可以覆盖包含可见和隐藏元素的控件中的 OnCreateAutomationPeer 方法,以返回您自己的 AutomationPeer。然后您可以覆盖 GetChildrenCore 方法并返回修改后的子集合。要更新自动化子树,您需要调用 AutomationPeer.ResetChildrenCache() 方法和 AutomationPeer.RaiseAutomationEvent(AutomationEvents.StructureChanged) 方法。