Back to Devexpress

GridAutomationHelper.AutomationRequested Attached Event

wpf-devexpress-dot-xpf-dot-grid-dot-automation-dot-gridautomationhelper.md

latest3.8 KB
Original Source

GridAutomationHelper.AutomationRequested Attached Event

Occurs when a UI Automation value is requested for the focused row or cell.

Namespace : DevExpress.Xpf.Grid.Automation

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

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

See AddAutomationRequestedHandler(DependencyObject, RoutedEventHandler) and RemoveAutomationRequestedHandler(DependencyObject, RoutedEventHandler).

Remarks

Handle the AutomationRequested event to override the value announced by screen readers when the target row or cell is focused.

The event exposes the following related data containers for corresponding scenarios:

Limitations

For GridControl and TreeListControl, attach the AutomationRequested event to the View ( TableView, CardView or TreeListView ).

If you use the TreeViewControl, attach the AutomationRequested event directly to the control.

Example

The following code example handles the AutomationRequested event and changes values announced by a screen reader app when the target 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) {
    if (e is RowAutomationEventArgs rowArgs) {
        var grid = rowArgs.DataControl as GridControl;
        var view = grid?.View as TableView;
        if (view == null)
            return;

        // Skip special rows
        if (rowArgs.RowHandle == DataControlBase.NewItemRowHandle ||
            rowArgs.RowHandle == DataControlBase.InvalidRowHandle)
            return;

        // "Header1 Value1, Header2 Value2, ..."
        var parts = view.VisibleColumns.Select(c => {
            var header = c.HeaderCaption ?? c.FieldName;
            var value = view.GetCellValue(rowArgs.RowHandle, c);
            return $"{header} {value}";
        });

        e.AutomationValue = string.Join(", ", parts);
    }
}

See Also

GridAutomationHelper Class

GridAutomationHelper Members

DevExpress.Xpf.Grid.Automation Namespace