2013-08-07 26 views
3

我需要讓我的應用程序視覺受損友好......而且我面臨這個問題:儘管Windows講述人儘管讀取了窗口中的所有控件名稱其中有些是隱藏的。Windows講述人讀取窗口中所有控件的名稱(甚至是隱藏的)

我有另一個應用程序,我用WinForms寫它,並在那裏工作正常。

在查看UI間諜後,我看到WinForms應用程序沒有公開隱藏的控件,WPF公開了窗口中的所有控件。

它可能是它是WPF中的錯誤?

回答

1

如果您的控件已經存在於可視樹中,則此行爲是正常的,因爲基於Visual樹的UI自動化樹。因此,如果您想阻止使用屏幕閱讀器閱讀不必要的元素,則必須按需加載它們。

您還可以覆蓋包含可見和隱藏元素的控件中的OnCreateAutomationPeer方法以返回您自己的AutomationPeer。然後,您可以覆蓋GetChildrenCore方法並返回修改的子集合。要更新自動化子樹,您需要調用AutomationPeer.ResetChildrenCache()方法和AutomationPeer.RaiseAutomationEvent(AutomationEvents.StructureChanged)之一。

2

我遇到了同樣的問題。 根據Alexis的回答,我寫了下面的代碼。這個對我有用。

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>(); 
    } 
} 
相關問題