更改 UWP TextBox 的屏幕 reader 行为?
Change screen reader behavior for UWP TextBox?
我编写了一个 UserControl,其工作方式类似于 PasswordBox,但使用 TextBox 实现。该控件替换字符,因为它们是用“点”字符键入的,用于我们不想显示实际内容的情况。它按预期工作,除了屏幕 reader 将读取输入的每个字符,这违背了目的。相比之下,当用户在 PasswordBox 中键入字符时,讲述人程序会说“隐藏”而不是键入的键。
当用户在 TextBox 中键入键时,我可以做些什么来改变屏幕的行为 reader?如果我能让它说“隐藏”就好了,但让屏幕 reader 什么都不说也很好。我查看了 AutomationProperties class 上的属性,但没有看到任何明显的内容。
当您编写 Windows 应用程序时,您用于 UI 的 classes 已经提供了 UI 自动化支持,它支持无障碍应用程序和辅助功能技术,例如 screen readers。 PasswordBox 的 Automation 是 PasswordBoxAutomationPeer,你可以检查 Default peer implementation 并在 PasswordBoxAutomationPeer 部分覆盖,它覆盖了 IsPassword 方法,它可以防止屏幕 reader 读取字符。
因此,您可以从 TextBox 派生自定义 class,并为您在自定义 class 中启用的其他功能添加自动化支持。然后覆盖 OnCreateAutomationPeer 以便它 returns 您的自定义对等体。例如:
public class MyCustomAutomationPeer : FrameworkElementAutomationPeer
{
public MyCustomAutomationPeer(MyTextBox owner) : base(owner)
{
}
protected override string GetClassNameCore()
{
return "MyTextBox";
}
protected override bool IsPasswordCore()
{
return true;
}
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Edit;
}
}
public class MyTextBox : TextBox
{
public MyTextBox()
{
// other initialization; DefaultStyleKey etc.
}
protected override AutomationPeer OnCreateAutomationPeer()
{
return new MyCustomAutomationPeer(this);
}
}
之后,您可以将在 MyTextBox 中键入的字符替换为“点”字符。另外,关于自定义自动化peer的更多细节,可以参考这个document.
我编写了一个 UserControl,其工作方式类似于 PasswordBox,但使用 TextBox 实现。该控件替换字符,因为它们是用“点”字符键入的,用于我们不想显示实际内容的情况。它按预期工作,除了屏幕 reader 将读取输入的每个字符,这违背了目的。相比之下,当用户在 PasswordBox 中键入字符时,讲述人程序会说“隐藏”而不是键入的键。
当用户在 TextBox 中键入键时,我可以做些什么来改变屏幕的行为 reader?如果我能让它说“隐藏”就好了,但让屏幕 reader 什么都不说也很好。我查看了 AutomationProperties class 上的属性,但没有看到任何明显的内容。
当您编写 Windows 应用程序时,您用于 UI 的 classes 已经提供了 UI 自动化支持,它支持无障碍应用程序和辅助功能技术,例如 screen readers。 PasswordBox 的 Automation 是 PasswordBoxAutomationPeer,你可以检查 Default peer implementation 并在 PasswordBoxAutomationPeer 部分覆盖,它覆盖了 IsPassword 方法,它可以防止屏幕 reader 读取字符。
因此,您可以从 TextBox 派生自定义 class,并为您在自定义 class 中启用的其他功能添加自动化支持。然后覆盖 OnCreateAutomationPeer 以便它 returns 您的自定义对等体。例如:
public class MyCustomAutomationPeer : FrameworkElementAutomationPeer
{
public MyCustomAutomationPeer(MyTextBox owner) : base(owner)
{
}
protected override string GetClassNameCore()
{
return "MyTextBox";
}
protected override bool IsPasswordCore()
{
return true;
}
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Edit;
}
}
public class MyTextBox : TextBox
{
public MyTextBox()
{
// other initialization; DefaultStyleKey etc.
}
protected override AutomationPeer OnCreateAutomationPeer()
{
return new MyCustomAutomationPeer(this);
}
}
之后,您可以将在 MyTextBox 中键入的字符替换为“点”字符。另外,关于自定义自动化peer的更多细节,可以参考这个document.