c# - Xamarin 形成可访问性订单
问题描述
我想更改 VoiceOver 和 Talkback 读取视图中元素的顺序。我发现TabIndex
应该设置页面中元素的焦点顺序,所以我尝试构建一个简单的示例应用程序,按照我想要的顺序设置不同的 TabIndex,但它似乎只适用于某些元素(如标签、按钮......)。我创建了一个随机元素,如红色 BoxView 并将其设置为可访问元素box2.SetValue(AutomationProperties.IsInAccessibleTreeProperty, true);
,但它始终将焦点作为最后一项,不知道为什么。比我想做一些事情来在附加的东西之后在代码中更改可访问性顺序。有什么建议吗?
XAML:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="AccessibilityFocus.MainPage">
<AbsoluteLayout x:Name="container">
<!-- Place new controls here -->
<Label x:Name="label1" Text="Label 1" TabIndex="10"/>
<BoxView x:Name="box2" BackgroundColor="Red" TabIndex="20"/>
<Label x:Name="label3" Text="Label 3" TabIndex="30"/>
<Button x:Name="buttonChange"
Text="CHANGE"
Clicked="changeFocus"
TabIndex="40"/>
</AbsoluteLayout>
</ContentPage>
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
namespace AccessibilityFocus
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
IList<View> _views;
public MainPage()
{
InitializeComponent();
_views = container.Children;
AbsoluteLayout.SetLayoutBounds(label1, new Rectangle(0.1, 0.2, 0.2, 0.2));
AbsoluteLayout.SetLayoutFlags(label1, AbsoluteLayoutFlags.All);
label1.SetValue(AutomationProperties.IsInAccessibleTreeProperty, true);
AbsoluteLayout.SetLayoutBounds(box2, new Rectangle(0.5, 0.2, 0.2, 0.2));
AbsoluteLayout.SetLayoutFlags(box2, AbsoluteLayoutFlags.All);
box2.SetValue(AutomationProperties.IsInAccessibleTreeProperty, true);
AutomationProperties.SetName(box2, "Red box");
AbsoluteLayout.SetLayoutBounds(label3, new Rectangle(0.9, 0.2, 0.2, 0.2));
AbsoluteLayout.SetLayoutFlags(label3, AbsoluteLayoutFlags.All);
label3.SetValue(AutomationProperties.IsInAccessibleTreeProperty, true);
AbsoluteLayout.SetLayoutBounds(buttonChange, new Rectangle(0.5, 0.7, 0.5, 0.2));
AbsoluteLayout.SetLayoutFlags(buttonChange, AbsoluteLayoutFlags.All);
_views.ForEach(v => Debug.WriteLine($"Indici: {v.TabIndex}"));
}
public void changeFocus(object sender, EventArgs e)
{
Debug.WriteLine("Cambio focus order");
//HERE I WOULD LIKE TO DO SOMETHING TO CHANGE THE ACCESSIBILITY ORDER
}
}
}
解决方案
推荐阅读
- python - 是否存在一个命令来提取列表的一部分并将其放在同一个列表的开头?
- python - 使用 ssh 为远程 Python 脚本传递参数
- javascript - 动画图像离开屏幕后,如何删除它们?
- javascript - 如何在 NodeJs 中实现异步
- lua - 为什么我的门在使用 TweenService() 的 ROBLOX Studio 中表现异常?
- java - 为什么 BigInteger 的 modPow 方法的性能会随着线程数的增加而降低?
- python - 如何让 docx2txt 处理目录中的所有 docx 文件?
- xml - 我可以用纯 XML 表达 IFML 模型吗?
- laravel - 如何在 Laravel 的控制器内使用多个中间件用户角色?
- arrays - 我可以将 = 用于 for 循环中的条件吗?