3

我有一个自定义控件。我喜欢为系统屏幕阅读支持提供支持。是否有任何逻辑可以发现我们的机器中启用了旁白或编码 UI 工具。??

4

2 回答 2

1

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

var isNarratorStarted = AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged);
于 2017-08-08T09:15:48.743 回答
1

我有类似的情况,但是在使用 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.
}
于 2017-08-25T11:31:07.310 回答