Making Your Xamarin.Forms Apps Accessible
Note: With the release of Xamarin.Forms 2.3.5-pre3, we have renamed the
Accessibility class’s name to
iOS, Android, and Windows all expose APIs for developers to build accessible mobile apps for everyone. We’re excited to announce that we’ve added new APIs for accessibility in Xamarin.Forms to make it even easier for developers to build accessible, cross-platform mobile applications. In this post, we’ll take a look at new APIs added to Xamarin.Forms that make it easy to build accessible mobile applications.
AutomationProperties APIs in Xamarin.Forms
Xamarin.Forms 2.3.5 provides a base set of hint-related accessibility APIs. They consist of the following:
By defining these properties, we can utilize the underlying accessibility functionality in iOS and Android, such as VoiceOver.
Making the Xamarin Evolve 2016 App Accessible
The easiest way to dig into how these new APIs work is with a real-world example. Let’s take the LoginPage from the Xamarin Evolve 2016 mobile application and make it accessible using the new APIs in Xamarin.Forms. In this layout, we have the usual Xamarin.Forms elements such as
Button. Prior to Xamarin.Forms 2.3.5, we would have to use platform effects or a custom renderer to utilize the accessibility APIs. With the new APIs, we just need to add a few properties and our mobile app becomes accessible:
Run the code on a physical device with accessibility functionality enabled, and the value you provided for
AutomationProperties.Hint will be spoken to the user. This uses VoiceOver on iOS; on Android, some controls, incuding
Button, unfortunately don’t behavior properly for reasons pertaining to Android itself, although an element such as
Slider will read a combination of the
To enable VoiceOver for iOS, navigate to Settings -> General -> Accessibility -> VoiceOver. For Android, install TalkBack which is very likely already installed on the device and can be enabled under Settings -> Accessibility -> Vision. Windows users can enable the Narrator under the Ease of Access option in Settings.
Remember, you’ll need to have Xamarin.Forms 2.3.5 added to all projects using Xamarin.Forms, including your iOS and Android projects. Note that the
AutomationProperties properties may not be available in IntelliSense, as these are attached properties.
As you’ve seen with the above example, adding just four properties to my control in XAML added hint-driven accessibility to my mobile apps. We encourage you to give these new APIs in Xamarin.Forms 2.3.5 a try, and let us know what you think! You can read more about the various accessibility features on each platform’s website (iOS, Android, Windows).