我有一个自定义控件。 我喜欢提供对系统屏幕阅读的支持。是否有任何逻辑可以找到我们的机器中启用了叙述者或编码的 UI 工具。??
您可以使用命名空间Windows.UI.Xaml.Automation.Peers
和此方法:
var isNarratorStarted = AutomationPeer.ListenerExists(AutomationEvents.AutomationFocusChanged);
我有类似的情况,但是在使用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.
}