WPF DataGrid Accessibility

Feb 19, 2010 at 11:29 PM

Does the WPF DataGrid support accessiblity applications (i.e. screen readers), namely, JAWS?

I am developing a WPF application that will be used in govenment offices. This means we are required to meet section 508 (Accessibility) guidelines. I haven't had any problems with WPF controls supporting accessiblity until the DataGrid. When I use a screen reader (JAWS) to read the contents in the data grid it only reads the underlying type name (i.e. MyCompany.MyApp.MyType) the grid is bound to (twice in a row in fact). I have tried to get it working but have not been successfull. Is this is bug in the WPF DataGrid or was it not designed to be accessible. Given the limited content in help docs and online about WPF DataGrid accessibility any help you can provide would be greatly apprecianted.

Some specifics about how I'm using the DataGrid:
ReadOnly, 3 Columns, bound to a collection of search objects.
Column1: DataGridTextColumn
Column2: DataGridTemplateColumn [Image] (AutomationProperties.Name used to describe image not working either)
Column3: DataGridTextColumn (Style set to wrap text)

Thanks!

-Thad

Mar 9, 2010 at 2:56 PM

I've been playing around with the WPF and Silverlight DataGrids in terms of accessibility and in particularly it's interaction with JAWS 11 (JAWS only began supporting UIA in version 11).  The WPF DataGrid seems to be pretty good with JAWS if you do the following:

override the ToString on your objects to give a useful description of the object e.g. return Forename + " " + Surname.

Then override the OnLoadingRow of the DataGrid to set the row header to the bound up object as follows:

 

public class MyDataGrid : DataGrid
{
protected override void OnLoadingRow(DataGridRowEventArgs e)
{
e.Row.Header = e.Row.DataContext;
base.OnLoadingRow(e);
}
}

public class MyDataGrid : DataGrid {

protected override void OnLoadingRow(DataGridRowEventArgs e)

{

e.Row.Header = e.Row.DataContext;

base.OnLoadingRow(e);

}

}

You also need to have the row headers visible in the DataGrid's HeaderVisibility although I set the RowHeaderStyle's width to be 0px.

Now JAWS 11 should read out row headers (your ToString overrides of the objects) when moving between rows, and the column header and cell value when moving between cells.

What I currently can't work out is how to set the AutomationProperties.Name property on the DataGridCells for DataGridTemplateColumns.  I was hoping it would be as simple as setting it on the column but unfortunately not.

The Silverlight DataGrid however is very poor in terms of accessibility support.  Microsoft claim that they are setting the necessary UIA properties (that they are) and raising the necessary UIA event.  Despite JAWS 11 working very well with the WPF DataGrid, it just won't read out anything of use for the Silverlight DataGrid so something isn't right.

Hope that helps and let me know if you know how to properly UIA those DataGridTemplateColumns.

Ben