Back to Devexpress

GridAutomationHelper Class

wpf-devexpress-dot-xpf-dot-grid-dot-automation-91b00c55.md

latest2.7 KB
Original Source

GridAutomationHelper Class

Exposes an attached routed event that allows you to customize UI Automation values for DevExpress WPF data controls.

Namespace : DevExpress.Xpf.Grid.Automation

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public class GridAutomationHelper
vb
Public Class GridAutomationHelper

Remarks

Handle the AutomationRequested attached event to replace default values announced by screen readers for focused elements.

Example

The following code example handles the AutomationRequested event and changes values announced by a screen reader app when the target cell or row is focused:

xaml
<dxg:GridControl ItemsSource="{Binding Items}">
    <dxg:GridControl.View>
        <dxg:TableView
            x:Name="tableView"
            NavigationStyle="Row"
            dxg:GridAutomationHelper.AutomationRequested="OnAutomationRequested"/>
    </dxg:GridControl.View>
</dxg:GridControl>
csharp
using DevExpress.Xpf.Grid;
using DevExpress.Xpf.Grid.Automation;

void OnAutomationRequested(object sender, AutomationEventArgs e) {
    switch(e) {
        case CellAutomationEventArgs cell:
            // Announce "<Header> <Value>" for the focused cell
            var header = cell.Column.HeaderCaption ?? cell.Column.FieldName;
            e.AutomationValue = $"{header} {cell.Cell.Value}";
            break;

        case RowAutomationEventArgs row:
            // Announce all visible column values for the focused row
            var view = (row.DataControl as GridControl)?.View as TableView;
            if(view != null) {
                var parts = view.VisibleColumns
                    .Select(c => $"{c.HeaderCaption ?? c.FieldName} {view.GetCellValue(row.RowHandle, c)}");
                e.AutomationValue = string.Join(", ", parts);
            }
            break;
    }
}

Inheritance

Object GridAutomationHelper

See Also

GridAutomationHelper Members

DevExpress.Xpf.Grid.Automation Namespace