Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf Windows叙述者读取窗口中所有控件(甚至隐藏控件)的名称_Wpf_Xaml_Wpf Controls_Hidden Field_Narrator - Fatal编程技术网

Wpf Windows叙述者读取窗口中所有控件(甚至隐藏控件)的名称

Wpf Windows叙述者读取窗口中所有控件(甚至隐藏控件)的名称,wpf,xaml,wpf-controls,hidden-field,narrator,Wpf,Xaml,Wpf Controls,Hidden Field,Narrator,我需要使我的申请对视力受损者友好。。。我面临着这个问题:Windows叙述者读取窗口中的所有控件名称,尽管其中一些控件是隐藏的 我有另一个应用程序,我用WinForms来编写它,在那里它工作得很好 在查看UI Spy之后,我看到WinForms应用程序没有公开隐藏的控件,而WPF公开了窗口中的所有控件 这可能是WPF中的错误吗?如果控件已经在可视化树中,则此行为是正常的,因为UI自动化树基于可视化树。因此,如果要防止使用屏幕阅读器读取不必要的元素,必须按需加载它们 您还可以在包含可见和隐藏元素的

我需要使我的申请对视力受损者友好。。。我面临着这个问题:Windows叙述者读取窗口中的所有控件名称,尽管其中一些控件是隐藏的

我有另一个应用程序,我用WinForms来编写它,在那里它工作得很好

在查看UI Spy之后,我看到WinForms应用程序没有公开隐藏的控件,而WPF公开了窗口中的所有控件


这可能是WPF中的错误吗?

如果控件已经在可视化树中,则此行为是正常的,因为UI自动化树基于可视化树。因此,如果要防止使用屏幕阅读器读取不必要的元素,必须按需加载它们


您还可以在包含可见和隐藏元素的控件中重写OnCreateAutomationPeer方法,以返回您自己的AutomationPeer。然后可以重写GetChildrenCore方法并返回修改后的子集合。要更新自动化子目录树,您需要调用AutomationPeer.ResetChildrenCache()方法和AutomationPeer.RaiseAutomationEvent(AutomationEvents.StructureChanged)方法。

我也遇到了同样的问题。 根据亚历克西斯的回答,我写了下面的代码。它对我有用

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>();
    }
}
公共类MyAutoComplete:RadAutoCompleteBox
{
公共MyAutoComplete()
{
//这里有很多东西
}
受保护的覆盖AutomationPeer OnCreateAutomationPeer()
{
返回新的MyAutomationPeer(此);
}
}
内部类MyAutomationPeer:RadAutoCompleteBoxAutomationPeer
{
公共MyAutomationPeer(FrameworkElement所有者)
:基地(所有者)
{
}
受保护的覆盖列表GetChildrenCore()
{
返回新列表();
}
}