Accessibility state in .NET MAUI
An accessibility state helps users of assistive technologies to understand the state of elements on the screen. The state selected
for example, indicates that an element has been selected. The screen reader announces the state of elements as it reads the screen. It is important to assign correct states of elements to avoid misunderstanding.
Accessibility state - .NET MAUI
In MAUI, there is no built-in support to indicate an accessibility state.
By intercepting the handler changed event, you can set the StateDescription
on Android or AccessibilityValue
on iOS.
CustomEntry.xaml
<Entry
x:Name="Field"
HandlerChanged="Entry_HandlerChanged"
Text="{Binding Text}" />
Partial class on Android:
public partial class PinTilesCodeEntryView
{
private AndroidX.AppCompat.Widget.AppCompatEditText? editor;
private void Entry_HandlerChanged(object? sender, EventArgs? e)
{
if (sender.Handler?.PlatformView is AndroidX.AppCompat.Widget.AppCompatEditText field)
{
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.R)
{
field.StateDescription = "Custom value";
}
}
}
}
Partial class on iOS:
CustomEntry.xaml.iOS.cs
private void Entry_HandlerChanged(object? sender, EventArgs? e)
{
if (sender.Handler?.PlatformView is UITextField field)
{
field.AccessibilityValue = "Custom value";
}
}