Partager via


Silverlight Accessibility Coding Practice

Accessibility is about making your applications usable by people with limitations that prevent or impede the use of conventional user interfaces. Microsoft Silverlight provides built-in keyboard support and support for screen readers, which leverages accessibility frameworks that already exist for use with HTML and other UI technologies. The built-in support enables a basic level of accessibility that you can customize with very little work by setting a handful of properties. For more information, you can refer to Silverlight Accessibility and Silverlight Accessibility for Developers.

Silverlight works with screen reader software out of the box. However, you will normally need to modify some settings for optimal behavior or to implement additional support. Here are some essentials to make this happen:

  • Windowless Mode - Using the Windowless Mode in Silverlight renders it inaccessible. Assistive Technology (AT) clients are unable to see the Silverlight application in the UI Automation Tree in this situation. Using the standard mode eliminates this issue.  The windowless mode property can be set by <param name="windowless" value="false"/> in the Silverlight object hosting page (aspx or html). Use the default should be fine if you haven't changed it yourself.
  • Set the AutomationProperties.Name of each UI control. For example: <TextBox x:Name="TextProductName” AutomationProperties.Name="Product Name"/>. It can also be set by doing data binding to a view model’s property. There are other ways to set the automation property for accessibility support. Refer to Silverlight Accessibility for more details.
  • Use IsTabStop, TabIndex, and TabNavigation to control Tab Stops in xaml or programmatically. TabNavigation has three values: Once, Local and Cycle. The default is “Once”. If your page uses data grid, tree view, or custom control that contains more than one UI elements, you may want to set TabNavigation=”Local” so that you can tab in, tab through all UI elements within the control and tab out at the end.
  • Control Focus – set default focus when page loads. For dynamically generated contents (e.g. add a row to a data grid), set the focus to the first actionable UI element (e.g. TextBox, CheckBox, Button, DropDown, etc.). If you use popup, set focus back to the wanted UI element when the popup closes.
  • Add similar support to your own custom controls.
  • In dynamically generated controls, you can set the automation property programmatically: AutomationProperties.SetName(DependencyObject element, string value).
  • Override the public override string ToString() of any data contract that are used by data binding so that the TA client can read it properly. For example, if you don’t do this, the items in dropdowns may not be read properly.
  • Try to avoid scrollbars. Use other options to accommodate large data or content. For example, use paging other than scrollbar with data grid.
  • Debugging: the user interface of a Silverlight application is represented by a visual tree of UI elements. You can view this accessibility tree using free tools such as UIA Verify or commercial tools such as Silverlight Spy. This is useful to confirm the values of the attached AutomationProperties.
  • Always use AT client (e.g. screen reader software) to test your application.