如何检测叙述者工具是否正在运行?

时间:2017-07-24 08:26:47

标签: coded-ui-tests screen-readers narrator

我有自定义控件。我想提供对系统屏幕阅读支持的支持。是否有任何逻辑可以找到我们的机器中启用了叙述者或编码的UI工具。??

2 个答案:

答案 0 :(得分:1)

您可以使用命名空间Windows.UI.Xaml.Automation.Peers和此方法:

var isNarratorStarted = AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged);

答案 1 :(得分:0)

我有类似的情况,但在使用UWP应用程序时我就这样解决了。也许你可以从这里拿东西:

private bool isAutomationPeerCreated = false;

private bool IsAutomationPeerAttached => this.isAutomationPeerCreated || AutomationPeer.ListenerExists(AutomationEvents.PropertyChanged);

//triggered everytime you run narrator or any other screen reading software that is based on accessing automation properties
protected override AutomationPeer OnCreateAutomationPeer()
{
    if(!this.IsAutomationPeerAttached)
    {
        this.isAutomationPeerCreated = true;
        this.OUR_LOGIC_BASED_ON_ATTACHED_NARRATOR();
    }
    return null;
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    base.OnNavigatedFrom(e);
    this.isAutomationPeerCreated = false;
}

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    if(IsAutomationPeerAttached)
    {
        this.OUR_LOGIC_BASED_ON_ATTACHED_NARRATOR();       
    }
}

private void OUR_LOGIC_BASED_ON_ATTACHED_NARRATOR()
{
    //DO STH.
}